call shell commands; synchronous return

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

call shell commands; synchronous return

Stephen-71
Hi,

The method I've been using for submitting shell commands is asynchronous...

For example:-
     shellCmd := '<long running shell command here>'.
     pipe := FileStream popen: shellCmd dir: FileStream read.

pipe returns after about a second no matter how long the shell command
takes to complete.

Is there a way to call shell commands in a synchronous fashion?

Thanks
Stephen


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: call shell commands; synchronous return

Paolo Bonzini-2
Stephen wrote:

> Hi,
>
> The method I've been using for submitting shell commands is asynchronous...
>
> For example:-
>     shellCmd := '<long running shell command here>'.
>     pipe := FileStream popen: shellCmd dir: FileStream read.
>
> pipe returns after about a second no matter how long the shell command
> takes to complete.
>
> Is there a way to call shell commands in a synchronous fashion?

Smalltalk system: 'abc'

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: call shell commands; synchronous return

Stephen-71

Paolo Bonzini wrote:
> Smalltalk system: 'abc'
>
> Paolo
>

Thanks

shellOut := Smalltalk system: 'sleep 5 && ls -l /etc && sleep 10'.
Transcript showCr: shellOut printString.

That worked a treat.

Is there anything one should be aware of when choosing between the two
ways of calling shell commands? The system: call above appeals since it
is synchronous and provides the shell output, but just wondering if
there is a situation when it is better to use the "Filestream popen:
dir" command.

And is there a way to get access to the standard error stream?

Thank you again

Stephen



_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: call shell commands; synchronous return

Stephen-71

>
> shellOut := Smalltalk system: 'sleep 5 && ls -l /etc && sleep 10'.
> Transcript showCr: shellOut printString.
>
> That worked a treat.
>
> Is there anything one should be aware of when choosing between the two
> ways of calling shell commands? The system: call above appeals since it
> is synchronous and provides the shell output, but just wondering if
> there is a situation when it is better to use the "Filestream popen:
> dir" command.
>

Then found that Smalltalk system: returns an integer rather than the
shell output.

So here is what I wanted to do:

" Part 1: shut down running VMWare VMs"
shellCmd := '/usr/bin/vmrun list'.
pipe := FileStream popen: shellCmd dir: FileStream read.
pipe linesDo: [: vmName |
    shellCmd2 := '/usr/bin/vmware-cmd %1 stop' bindWith: vmName.
    pipe2 := FileStream popen: shellCmd2 dir: FileStream read.     ]

Hence the need for a synchronous call so that the script waits until
each machine is shut down.


Thanks
Stephen


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: call shell commands; synchronous return

Paolo Bonzini-2

> So here is what I wanted to do:
>
> " Part 1: shut down running VMWare VMs"
> shellCmd := '/usr/bin/vmrun list'.
> pipe := FileStream popen: shellCmd dir: FileStream read.
> pipe linesDo: [: vmName |
>    shellCmd2 := '/usr/bin/vmware-cmd %1 stop' bindWith: vmName.
>    pipe2 := FileStream popen: shellCmd2 dir: FileStream read.     ]
>
> Hence the need for a synchronous call so that the script waits until
> each machine is shut down.

Do you need the output of the second command?  If no, obviously you can
use popen for the outer loop and system for the inner loop.  Otherwise,
closing a pipe or sending it #contents will also wait for the process to
end.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk