[Newbies] Reading context from UnixProcess
David T. Lewis
lewis at mail.msen.com
Mon Apr 7 20:30:44 UTC 2008
On Sun, Apr 06, 2008 at 10:47:29PM -0600, Jim O'Connor wrote:
> I'm having trouble figuring out how to collect input from an externally
> executed linux process.
> The simple example below should, I think let me dump the contents
> of the directory /etc. The stream type returned by initialStdOut is
> AttachableFileStream. Sending the contents message to it generates
> a primitive error, caused I think because the stream's instance variable
> position turns out to be nil on inspection.
> p := UnixProcess command: 'ls -l /etc/'
> s := p initialStdOut
> s contents
> What am I doing wrong or missing?
> Better would be if someone has a simple code snippet the executes an
> external process and then accepts output from it asynchronously.
A good way to do this is to use a PipeableOSProcess, which provides a
higher-level wrapper around the UnixProcess and takes care of setting
up all the pipes between Squeak and the external process. You will
need to load the CommandShell package in addition to the OSProcess
package in order to get this.
Once you have loaded CommandShell, try inspecting this expression:
ProxyPipeline command: 'ls -l /etc'
You can read the command output directly from the resulting
I am not near a Squeak computer at the moment, so apologies in advance
if I have misremembered the details above. In any case, you will find
a number of examples on the class side of ProxyPipeline and a few of
the other classes in CommandShell and OSProcess.
More information about the Beginners