Open Process command

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Open Process command

Post by rblackmore245 » Fri Apr 07, 2017 4:45 pm

Can someone post an example script of how to read from this ?

For example I want to be able to use a command line application in windows and get the console strout output and display this in a field just like you would see in the command line window.

E.G a ping -t www.google.co.uk

There is hardly any documentation on how to read a text output from this.

Klaus
Posts: 10295
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Open Process command

Post by Klaus » Fri Apr 07, 2017 4:54 pm

Hi rblackmore245,

just tried it at home (on my Mac, but the same applies to Windows!) and had success with this script:

Code: Select all

on mouseUp
   get shell("ping -t 2 www.google.co.uk")
   put IT & CR & the result into fld 1
end mouseUp
So I think THE RESULT contains the output of the SHELL command.

Hope that helps!


Best

Klaus

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Open Process command

Post by rblackmore245 » Mon Apr 10, 2017 9:53 am

Thanks for your reply.

Yes I have used the shell command before but looking for something that will give a constant output from a process which I believe this function will work.

http://livecode.wikia.com/wiki/Open_process

I am able to get the process to open but unable to get the result or poll for the result at an interval.

Klaus
Posts: 10295
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Open Process command

Post by Klaus » Mon Apr 10, 2017 10:49 am

Ah, I see, but that stuff is unfortunalely over my head. 8)

MaxV
Posts: 1535
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Open Process command

Post by MaxV » Mon Apr 10, 2017 10:51 am

Hi,
you can't pass parameter with open process, so you have to write the process with options on a file and launch it.
Here a working example on windows:
To launch the process, double check that you are in a writing folder (using defaultFolder), and then:

Code: Select all

put "ping  -t  www.google.co.uk" into URL "file:myProcess.bat"
open process "myProcess.bat" for text read
to read 5 lines of the output:

Code: Select all

 read from process "myProcess.bat" for 5 lines
put it into field "process output"
to close process:

Code: Select all

close process "myProcess.bat" 
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Open Process command

Post by rblackmore245 » Mon Apr 10, 2017 2:58 pm

Thank you that works great but is there anyway to make it work asynchronous so it does not wait for the expected output and pause the stack and pause all scripts

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6110
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Open Process command

Post by FourthWorld » Mon Apr 10, 2017 3:20 pm

The "open process" command can be for "read", "write", "both" or "neither", IIRC "neither" will spawn the process and return immediately without waiting for a result.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

MaxV
Posts: 1535
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Open Process command

Post by MaxV » Mon Apr 10, 2017 5:20 pm

rblackmore245 wrote:Thank you that works great but is there anyway to make it work asynchronous so it does not wait for the expected output and pause the stack and pause all scripts
The example code:

Code: Select all

put "ping  -t  www.google.co.uk" into URL "file:myProcess.bat"
open process "myProcess.bat" for text read
doesn't block the script, you can do else.
When you want to see what happen, then you use the read from process code.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Windows”