Page 1 of 1
Run shell command but not wait for result
Posted: Thu Jun 09, 2016 8:45 am
by kaveh1000
I am using the following command:
It seems LiveCode waits until the result is in temp, then executes the next command. Actually I am not interested in the result. I want the shell script to be sent, then continue with the next command.
Can I have some advice on this please.
Re: Run shell command but not wait for result
Posted: Thu Jun 09, 2016 9:52 am
by Thierry
kaveh1000 wrote:I am using the following command:
I want the shell script to be sent, then continue with the next command.
Can I have some advice on this please.
Mmm, is this what you want?
Code: Select all
get shell( "shellCommand1;shellCommand2;shellCommand3")
EDIT: Oops, missed that you want asynchronous calls.
So, I change my answer
But this is not perfect for every use cases.
HTH,
Thierry
Re: Run shell command but not wait for result
Posted: Thu Jun 09, 2016 10:03 am
by ghettocottage
I seem to remember having a similar issue, and solved it by running an external bash script rather than running the commands directly from within livecode.
Re: Run shell command but not wait for result
Posted: Thu Jun 09, 2016 11:53 am
by Klaus
ghettocottage wrote:I seem to remember having a similar issue, and solved it by running an external bash script rather than running the commands directly from within livecode.
Yes, direct SHELL calls from within LC are always blocking!
Re: Run shell command but not wait for result
Posted: Thu Jun 09, 2016 12:21 pm
by kaveh1000
Klaus wrote:ghettocottage wrote:I seem to remember having a similar issue, and solved it by running an external bash script rather than running the commands directly from within livecode.
Yes, direct SHELL calls from within LC are always blocking!
So LC will always wait for the result of the Shell command before continuing with next?
Re: Run shell command but not wait for result
Posted: Thu Jun 09, 2016 12:23 pm
by Thierry
kaveh1000 wrote:Klaus wrote:
Yes, direct SHELL calls from within LC are always blocking!
So LC will always wait for the result of the Shell command before continuing with next?
Yes, that the way it works.
Thierry
Re: Run shell command but not wait for result
Posted: Thu Jun 09, 2016 4:53 pm
by FourthWorld
In some cases you can use "open process" instead. The "for neither" option will wait for neither read nor write, returning to the handler once the process is launched.
Re: Run shell command but not wait for result
Posted: Fri Jun 10, 2016 5:57 am
by wsamples
You can get non-blocking shell commands in Livecode although this may be platform dependent. This isn't my idea, it comes from howsoft.com,
http://www.howsoft.com/runrev/extensions/ "Shell without wait".
Code: Select all
put "YOUR-SHELL-COMMAND" into tShellCommand
put "exec " & tShellCommand & " > /dev/null 2>/dev/null &" into tNoWaitShellCommand
get shell(tNoWaitShellCommand)
Re: Run shell command but not wait for result
Posted: Fri Jun 10, 2016 7:25 am
by Thierry
wsamples wrote:You can get non-blocking shell commands in Livecode although this may be platform dependent. This isn't my idea, it comes from howsoft.com,
http://www.howsoft.com/runrev/extensions/ "Shell without wait".
Code: Select all
put "YOUR-SHELL-COMMAND" into tShellCommand
put "exec " & tShellCommand & " > /dev/null 2>/dev/null &" into tNoWaitShellCommand
get shell(tNoWaitShellCommand)
I've been doing this a lot in the past and it can get tricky
depending on the scripts you are running...
Anyway, if you want to go that way, might be good
to check for nohup, screen and jobs commands.
But as I said, depends of your goal; hard to generalize.
Good luck,
Thierry
Re: Run shell command but not wait for result
Posted: Fri Jun 10, 2016 9:41 am
by kaveh1000
Thanks a lot all. We'll do some testing and report back if a good solution is found...