[Newbies] PipeableOSProcess incremental output

David T. Lewis lewis at mail.msen.com
Fri Oct 28 13:04:08 UTC 2011


On Thu, Oct 27, 2011 at 04:58:34PM -0700, Sean P. DeNigris wrote:
> How do I get the output and error of a PipeableOSProcess command line-by-line
> as it comes, like CommandShell does?
> 

In PipeableOSProcess, the output stream is #pipeFromOutput and
the error stream is #errorPipelineStream. For example:

  proc := PipeableOSProcess command: 'ls -l * NOSUCHFILE'.
  out := proc pipeFromOutput.
  err := proc errorPipelineStream.

>From any of these streams you can read character by character
with #next, or you can read the entire contents of the stream
with #upToEnd or #upToEndOfFile. On a unix system, lines of
output in a pipe will usually be separated by line feed characters,
so you can read character by character looking for a Character lf.

But actually you do not even need to access those streams
directly, because PipeableOSProcess itself behaves like a stream.
You can read output directly from a PipeableOSProcess with
#next, #next:, #upToEnd, #upToEndOfFile, #errorUpToEnd, and
#errorUpToEndOfFile.

To illustrate the idea, one way to get the output of a command
line by line as follows:

  (PipeableOSProcess command: 'ls -l') 
       upToEndOfFile findTokens: String lf

> I found #setNonBlockingOutput for the output, but "pipeFromError
> setNonBlocking" doesn't seem to do the same for the errors.
>

In PipeableOSProcess this is all handled automatically, so
you can just use the output and error streams as described
above.

Dave
 


More information about the Beginners mailing list