<div dir="ltr"><div>Hi Dave,</div><div><br></div><div>Thanks for the comprehensive explanation and examples. I'm using Squeak 6.1 here, which might be an issue, but the following message responds with a DNU:</div><div><br></div><div>OSProcess outputOf: 'which node'</div><div><br></div><div>I don't see any method in the system called #outputOf:</div><div><br></div><div>I installed OSProcess and CommandShell via the optional additions during the setup wizard.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Aug 27, 2022 at 10:36 AM David T. Lewis <<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Eric,<br>
<br>
Maybe it will help if I also give an example of Squeak interacting with<br>
an external program through stdio pipes Here I will use /bin/bash as the<br>
exteral program. You would want to substitute that with the full path<br>
to whatever program you are actually trying to run.<br>
<br>
You can experiment with the example below by copying it into a workspace:<br>
<br>
<br>
    "Create an external OS process running the /bin/bash program. The<br>
    program will be connected to Squeak through stdio pipes."<br>
    bashProxy := PipeableOSProcess command: '/bin/bash'.<br>
<br>
    "Send a command line to the bash program, followed by a line<br>
    terminator, and flush the stream so the command is available to<br>
    the bash program."<br>
    bashProxy nextPutAll: 'who'; nextPut: Character lf; flush. <br>
<br>
    "Wait a short time to give the bash program time to run, and to send<br>
    the result back to Squeak."<br>
    (Delay forMilliseconds: 20) wait.<br>
<br>
    "Read all available data from the stdout stream of the bash process.<br>
    Note also methods #errorUpToEndOfFile, #upToEndOfFile."<br>
    bashProxy upToEnd.<br>
<br>
    "When you are done interacting with your bash program, close it and<br>
    allow the external process to exit."<br>
    bashProxy close<br>
<br>
Dave<br>
<br>
On Fri, Aug 26, 2022 at 11:19:04PM -0400, David T. Lewis wrote:<br>
> Hi Eric and Tom,<br>
> <br>
> On Fri, Aug 26, 2022 at 04:27:56PM -0400, Eric Gade wrote:<br>
> > I believe what is happening is that the various #command: messages in<br>
> > OSProcess classes are executing without searching my PATH. Even if I add a<br>
> > copy of the current running process environment and set that as the<br>
> > environment of a new PipeableOSProcess, for example, I can't even get a<br>
> > result for `which node`. I can see that /usr/bin and /usr/sbin are on the<br>
> > path from within Squeak.<br>
> > <br>
> <br>
> Yes that is correct. On a unix system, the interpretation of PATH (and<br>
> lots of other things) are done by the shell, which is typically an<br>
> executable program such as /bin/bash. The actual programs and commands<br>
> that you run on a unix system are subprocesses of that shell program.<br>
> So the shell interprets the PATH and uses it to find the program that<br>
> you want to run.<br>
> <br>
> In Squeak with OSProcess, your Squeak virtual machine is the "shell"<br>
> and you can directly run programs by creating subprocesses of the VM<br>
> process. Of course, you can chose to run the executable program<br>
> /bin/bash, in which case you have a real unix shell, and you can let<br>
> that shell run other commands in the normal way.<br>
> <br>
> You can also run any other executable directly (and I think this is<br>
> what you have been doing). In that case there is no unix shell program<br>
> involved, and you would need to specify the fully qualified path to<br>
> the program, and you would need to do any necessary command parameter<br>
> expansion that would otherwise have been done by the unix shell.<br>
> <br>
> In OSProcess/CommandShell there is also a pure Smalltalk emulation<br>
> of a simple unix shell. This is by no means a complete emulation of<br>
> /bin/bash but it is sufficient to handle things like PATH expansion<br>
> and command pipeline composition without requiring the actual<br>
> /bin/bash shell.<br>
> <br>
> So to tie the pieces together, if you want to run the command "which node"<br>
> you can do this:<br>
> <br>
>   OSProcess outputOf: 'which node'<br>
> <br>
> This uses a CommandShell in Squeak to do the shell processing to<br>
> locate and run the program /usr/bin/which (so no need for /bin/bash).<br>
> It takes some patience but if you step through this it a debugger<br>
> you will be able to see what is going on. The Smalltalk command<br>
> shell emulation sets everything up so that OSProcess can run the<br>
> /usr/bin/which program as a direct subprocess of the Squeak VM.<br>
> <br>
> > Another example is that `PipeableOSProcess class >> #unixCommandPipeLine`<br>
> > responds with an empty string when I inspect it.<br>
> > <br>
> > Might this all be related to newer macOS settings somehow?<br>
> > <br>
> <br>
> This method is just an example to show how to compose a command pipeline<br>
> with some programs that would be found on a typical Unix/Linux system.<br>
> I'm not sure what it does on Mac.  It uses the programs 'ps', 'grep',<br>
> and 'cut', so if any of these is not found on your system, it probably<br>
> will just give an empty string in the output (plus some error output<br>
> that you can probably find if you dig through it in a debugger).<br>
> <br>
> Dave<br>
> <br>
> <br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Eric</div></div></div>