[squeak-dev] OSProcess streaming and early termination

David T. Lewis lewis at mail.msen.com
Sat Dec 8 16:51:47 UTC 2012


On Sat, Dec 08, 2012 at 10:55:41AM -0500, David T. Lewis wrote:
> On Sat, Dec 08, 2012 at 09:16:46AM +0100, Bert Freudenberg wrote:
> > On 08.12.2012, at 03:10, "David T. Lewis" <lewis at mail.msen.com> wrote:
> > > 
> > >  cmd := 'od -v -t x1 ', (Smalltalk imageName copyAfterLast: $/) asVmPathName.
> > >  pipeline := ProxyPipeline command: cmd.
> > >  data := pipeline next: 1000.
> > >  pipeline closePipes.
> > >  data inspect
> > 
> > Okay, that looks a lot simpler. But with the string interface I have to worry about argument escaping. That's why I wanted to use the array interface, and avoid a shell. Constructing a sanitized string from user data is very hard, and made unnecessary bybusing a non-interpreted interface.
> > 
> > Also, as I wrote I need to be able to set the working directory (and potentially the environment). Your example only works accidentally because you launched squeak from the image directory.
> > 
> 
> This does not directly answer your question, but here is a way to
> evaluate the command in a specified directory:
> 
>   file := 'squeak'.
>   path := '/usr/local/bin'.
>   cs := CommandShell new workingDirectory: path.
>   cmd := 'od -v -t x1 ', file.
>   pipeline := ProxyPipeline command: cmd shell: cs.
>   data := pipeline next: 50.
>   pipeline closePipes.
>   data ==> '0000000 23 21 2f 62 69 6e 2f 73 68 0a 23 20 0a 23 '
>   pipeline errorUpToEnd ==> ''
>  
> Or the same thing with file not found in that directory:
>  
>   file := 'noSuchFile'.
>   path := '/usr/local/bin'.
>   cs := CommandShell new workingDirectory: path.
>   cmd := 'od -v -t x1 ', file.
>   pipeline := ProxyPipeline command: cmd shell: cs.
>   data := pipeline next: 50.
>   pipeline closePipes.
>   data ==> ''
>   pipeline errorUpToEnd ==> '/usr/bin/od: noSuchFile: No such file or directory
>   '
> 

And if you will forgive yet another answer to the question that you
did not ask, here is a way to set an environment variable:

  cs := CommandShell new workingDirectory: '/usr/local/bin'.
  cs environment at: #FOO put: 'BAR'.
  cmd := '/usr/bin/env | grep FOO'.
  pipeline := ProxyPipeline command: cmd shell: cs.
  data := pipeline upToEndOfFile.
  pipeline closePipes.
  data ==> 'FOO=BAR
  '

Dave



More information about the Squeak-dev mailing list