Question

I am using the following code to read an error message from a byte array and it works fine the first time but if I try to access it the second time it throws an error:

errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);

StandardError is of type InboundPipe?

The error is:

Error: Error #3212: Cannot perform operation on a NativeProcess that is not running.

even though the process is running (process.running is true). It's on the second call to readUTFBytes that seems to be the cause.

Update:
Here is the code calling the same call one after another. The error happens on the next line and process.running has not changed from true. Happens on the second call.

errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);

I also found out the standardError is a InboundPipe instance and implements IDataInput.

Update 2:
Thanks for all the help. I found this documentation when viewing the bytesAvailable property.

[Read Only] Returns the number of bytes of data available for reading in the input buffer. User code must call bytesAvailable to ensure that sufficient data is available before trying to read it with one of the read methods.

When I call readUTFBytes() it resets the bytes available to 0. So when I read it a second time and there are no bytes available it causes the error. The error is or may be incorrect in my opinion or the native process.running flag is incorrect.

I looked into seeing if it has a position property and it does not, at least not in this instance.

Was it helpful?

Solution 2

This was a tricky problem since the object was not a byte array although it looks and acts like one (same methods and almost same properties). It is an InboundPipe that also implements IDataInput.

I found this documentation when viewing the bytesAvailable property.

[Read Only] Returns the number of bytes of data available for reading in the input buffer. User code must call bytesAvailable to ensure that sufficient data is available before trying to read it with one of the read methods.

When I call readUTFBytes() it resets the bytes available to 0. So when I call it a second time and there are no bytes available it causes the error. The error is or may be incorrect in my opinion or the native process.running flag is incorrect although I have reason to believe it's the former.

The solution is to check bytesAvailable before calling read operations and store the value if it needs to be accessed later.

if (process.standardError.bytesAvailable) {
    errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
    errorDataArray.push(errorData);
}

I looked into seeing if it has a position property and it does not, at least not in this instance.

OTHER TIPS

Could you try to set position to zero before reading process, especially before repetitive access:

Moves, or returns the current position, in bytes, of the file pointer into the ByteArray object. This is the point at which the next call to a read method starts reading or a write method starts writing.

//ByteArray example
var source: String = "Some data";
var data: ByteArray = new ByteArray();
data.writeUTFBytes(source);
data.position = 0;
trace(data.readUTFBytes(data.bytesAvailable));
data.position = 0;
trace(data.readUTFBytes(data.bytesAvailable));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top