Run shell command but not wait for result

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Run shell command but not wait for result

Post by kaveh1000 » Thu Jun 09, 2016 8:45 am

I am using the following command:

Code: Select all

put shell(Script_Shell) into temp
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.
Kaveh

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Run shell command but not wait for result

Post by Thierry » Thu Jun 09, 2016 9:52 am

kaveh1000 wrote:I am using the following command:

Code: Select all

put shell(Script_Shell) into temp
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
Last edited by Thierry on Thu Jun 09, 2016 6:39 pm, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

Re: Run shell command but not wait for result

Post by ghettocottage » Thu Jun 09, 2016 10:03 am

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.

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Run shell command but not wait for result

Post by Klaus » Thu Jun 09, 2016 11:53 am

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!

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Run shell command but not wait for result

Post by kaveh1000 » Thu Jun 09, 2016 12:21 pm

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?
Kaveh

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Run shell command but not wait for result

Post by Thierry » Thu Jun 09, 2016 12:23 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Run shell command but not wait for result

Post by FourthWorld » Thu Jun 09, 2016 4:53 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

wsamples
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 264
Joined: Mon May 18, 2009 4:12 am

Re: Run shell command but not wait for result

Post by wsamples » Fri Jun 10, 2016 5:57 am

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)

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Run shell command but not wait for result

Post by Thierry » Fri Jun 10, 2016 7:25 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Run shell command but not wait for result

Post by kaveh1000 » Fri Jun 10, 2016 9:41 am

Thanks a lot all. We'll do some testing and report back if a good solution is found...
Kaveh

Post Reply