[squeak-dev] OSProcess streaming and early termination

David T. Lewis lewis at mail.msen.com
Sat Dec 8 15:55:41 UTC 2012


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
  '

Dave



More information about the Squeak-dev mailing list