Use Shell Command from Pharo

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

Use Shell Command from Pharo

g_ongenae
Hello,

I would like to use execute shell command from Pharo.
I found OSProcess to do that but it doesn't work.

Thanks.
--
Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

Peter Uhnak
You need to be a bit more descriptive of what "doesn't work" mean, otherwise we can't help you. :)



Peter

On Fri, Mar 18, 2016 at 2:45 PM, Guillaume Ongenae <[hidden email]> wrote:
Hello,

I would like to use execute shell command from Pharo.
I found OSProcess to do that but it doesn't work.

Thanks.
--

Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

Mariano Martinez Peck
HI Guillaume,

I don't have much to add to what Peter said.  
As for OSProcess yes, we have some problems in latest VMs / images. At some point stdout redirection was not working. Then it seems it got fixed but now I am not sure if it is working as there were other people reporting it didn't work. 

As for OSSubprocess, if you are using Pharo 5.0, then it should work. If you have questions (the docs cover quite some questions), please let me know.



On Fri, Mar 18, 2016 at 10:51 AM, Peter Uhnák <[hidden email]> wrote:
You need to be a bit more descriptive of what "doesn't work" mean, otherwise we can't help you. :)



Peter

On Fri, Mar 18, 2016 at 2:45 PM, Guillaume Ongenae <[hidden email]> wrote:
Hello,

I would like to use execute shell command from Pharo.
I found OSProcess to do that but it doesn't work.

Thanks.
--




--
Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

g_ongenae
In reply to this post by Peter Uhnak
Thanks for the answer,

I've already seen this page. And the problem is when I do : OSProcess command: 'touch files.txt',
I can't find the created files. But I don't have any error message.

For the new lib, I'm working on Pharo 4, and it only works and version 5.

--
Guillaume
Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

John Pfersich
if you do something like this:

| p d  |
p := (PipeableOSProcess command: 'touch files.txt').
p keepInitialStdOutOpen: true.
d := Delay forMilliseconds: 250.
d wait.
[Transcript show: (p next: 300); flush. p atEnd] whileFalse: [d wait].
Transcript show: (p errorUpToEnd).
p closeOutput.

then you'll get this for output:

touch: files.txt: Permission denied

because you're trying to do a touch in the root directory

On Fri, Mar 18, 2016 at 6:41 AM, g_ongenae <[hidden email]> wrote:
Thanks for the answer,

I've already seen this page. And the problem is when I do : OSProcess
command: 'touch files.txt',
I can't find the created files. But I don't have any error message.

For the new lib, I'm working on Pharo 4, and it only works and version 5.

--
Guillaume



--
View this message in context: http://forum.world.st/Use-Shell-Command-from-Pharo-tp4885330p4885334.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

John Pfersich
continued...
(this is on Mac OSX, but it should be the same on any *nix). I don't do Windows. If you want to see the file try 
touch ~/files.txt 

By the way, the code above works in Pharo 4.0, should work with the latest Pharo 5.0 beta, but I haven't tested the code above with Pharo 5.0.

On Fri, Mar 18, 2016 at 10:35 PM, john pfersich <[hidden email]> wrote:
if you do something like this:

| p d  |
p := (PipeableOSProcess command: 'touch files.txt').
p keepInitialStdOutOpen: true.
d := Delay forMilliseconds: 250.
d wait.
[Transcript show: (p next: 300); flush. p atEnd] whileFalse: [d wait].
Transcript show: (p errorUpToEnd).
p closeOutput.

then you'll get this for output:

touch: files.txt: Permission denied

because you're trying to do a touch in the root directory

On Fri, Mar 18, 2016 at 6:41 AM, g_ongenae <[hidden email]> wrote:
Thanks for the answer,

I've already seen this page. And the problem is when I do : OSProcess
command: 'touch files.txt',
I can't find the created files. But I don't have any error message.

For the new lib, I'm working on Pharo 4, and it only works and version 5.

--
Guillaume



--
View this message in context: http://forum.world.st/Use-Shell-Command-from-Pharo-tp4885330p4885334.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

Peter Uhnak


On Sat, Mar 19, 2016 at 9:16 AM, john pfersich <[hidden email]> wrote:
continued...
(this is on Mac OSX, but it should be the same on any *nix). 

I don't actually see the reason why it should assume root folder if you don't specify a path… that's stupid on many levels (I blame mac).
On Linux you get home, although that's imho also wrong and it should use the folder of the image… but maybe that's a misconfiguration of OSProcess.

Peter
Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

Damien Pollet-2
On 19 March 2016 at 16:45, Peter Uhnák <[hidden email]> wrote:
I don't actually see the reason why it should assume root folder if you don't specify a path… that's stupid on many levels (I blame mac).

It's root because that's where the system launches applications from, when you double-click them in the Finder (or via the open command, I think). You'll see that GUI-launched images do not inherit your shell environment either.

However, if you run pharo from command-line, you get the usual unix behavior.
 
On Linux you get home, although that's imho also wrong and it should use the folder of the image… but maybe that's a misconfiguration of OSProcess.

No, it's the same logic than on Mac (albeit $HOME is arguably a little more sensible than the filesystem's root).

I'm not sure what's the correct behavior here, unless there is a way to know if pharo was launched from GUI (where working directory is meaningless and pharo should probably chdir() to the image directory) or from command-line (where the working directory is meaningful and should be honored. On OSX, maybe there's a way to pass GUI-specific arguments, through the Info.plist file?
Reply | Threaded
Open this post in threaded view
|

Re: Use Shell Command from Pharo

Dale Henrichs-3
I seem to recall that on the mac there was a system option of some sort that "launches apps from a sensible" location --- of course the Apple powers that be may have removed that capability recently...

Dale

On 3/19/16 9:41 AM, Damien Pollet wrote:
On 19 March 2016 at 16:45, Peter Uhnák <[hidden email]> wrote:
I don't actually see the reason why it should assume root folder if you don't specify a path… that's stupid on many levels (I blame mac).

It's root because that's where the system launches applications from, when you double-click them in the Finder (or via the open command, I think). You'll see that GUI-launched images do not inherit your shell environment either.

However, if you run pharo from command-line, you get the usual unix behavior.
 
On Linux you get home, although that's imho also wrong and it should use the folder of the image… but maybe that's a misconfiguration of OSProcess.

No, it's the same logic than on Mac (albeit $HOME is arguably a little more sensible than the filesystem's root).

I'm not sure what's the correct behavior here, unless there is a way to know if pharo was launched from GUI (where working directory is meaningless and pharo should probably chdir() to the image directory) or from command-line (where the working directory is meaningful and should be honored. On OSX, maybe there's a way to pass GUI-specific arguments, through the Info.plist file?