Shell DataAvailable

Good morning (o;

Have here a simple Python script that prints out numbers from 0 to 9 in one second interval.

How is the DataAvailable supposed to work?

Does it fire when a new line of text is received?
Or when the shell process is completed?

The Xojo documentation says only:

DataAvailable
Occurs when additional data has come into the internal receive buffer.

thanx in advance
richard

Usually, you get larger amounts of text back from the shell in multiple events of DataAvailable. When the shell is finished then you get the ShellCompleted event. But you get those only for an async shell.

No and no. When the event fires, you get some data. Could be any amount. If your data is line-oriented (as mine is), you have to have a method which will return you a line, and inside, the method has to accumulate data until it finds the end of line, and then returns that.

It’s not predictable, so your code needs to be prepared for DataAvailable to fire at any time, with any amount of data, broken up into arbitrary chunks. The only guarantee is that the chunks of data are delivered in their proper order.

Essentially, DataAvailable fires whenever two conditions are met: A) the shell command has emitted some data, and B) the framework schedules time to poll the shell and check for data and fire any necessary events. It is possible to force the framework to poll the shell via Shell.Poll, but you have to be very careful to prevent feedback loops that can lead to StackOverflow exceptions if there is any way that Shell.Poll could be triggered via any of the Shell events (DataAvailable, etc). It is generally better to let the framework schedule the polling on its own and build your code to be very tolerant.

Actually I set the Mode of the shell to “Interactive” and use the events DataAvailable for displaying the output in a log console TextArea and the Completion event for setting the Button who triggered the shell.

My console TextArea is updated as lines are coming in from shell commands.

Works very well with a python test script as well with the yosys FPGA synthesizer command (o;