Launch - Houston, we have a problem

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 115
Joined: Wed Apr 08, 2009 11:54 pm

Launch - Houston, we have a problem

Post by dickey » Fri Oct 23, 2009 1:14 pm

Hello all,

I use launch to run batch (.bat) files that are dynamically written in Rev. Batch files are run using command.com (the command prompt in windows). In my case I use the batch files to execute PHP scripts using the command line interface (CLI) in PHP. This is fantastic as it allows me to run numerous simultaneous processes. FYI: The PHP CLI itself also supports multi-threading (since PHP5). Once each batch file has completed execution, each command.com window simply closes.

I have built a control panel of sorts in Rev to gather the settings (criteria etc) that I pass as arguments to PHP via the batch file. In respect of my UI, I would like to 'tick' off the completed tasks, but to do so I need some intelligence on the application instances I have launch-ed from Rev.

Is there a way to identify an application instance spawned with launch, and further detect the status of an application instance opened with launch. This would allow me to update the user interface at 'mission control' with news about each individual mission. :wink:

Sample code...generic implementation

Code: Select all

  open file tBatchFile for write
  put "cd\"&cr into varContent
  put "cd Program Files\PHP5"&cr after varContent
  put "php.exe -f somephpfile.php" && quote & tSomeStringArgument & quote && tSomeNumericArgument && quote & tAnotherStringArgument & quote after varContent
  write varContent to file tBatchFile
  close file tBatchFile
  launch document tBatchFile
Any assistance greatly appreciated.

Kind regards, Andrew

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 23, 2009 8:55 pm

Hi Dickey,

You could write a value to a file and poll the data in this file from Revolution. This might cause execution errors though, if Revolution tried to access the file while data is being written to it by the batch process. Otherwise, there isn't really a way to do this, unless you can find a way to make the batch process and Revolution communicate through sockets.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 115
Joined: Wed Apr 08, 2009 11:54 pm

Launch - Houston, we have a problem

Post by dickey » Sat Oct 24, 2009 2:16 am

Thank you for replying Mark,

Yes, I had figured as much. I had already implemented a final call in my PHP scripts to update a status table in my database reflecting the success or failure of each batch process. Therefore, if processing continues to that point in the php script, success!. I had coded Rev to query the database either on demand: 1. a refresh button or 2. once every couple of minutes. These measures are adequate for the task, however I guess I was fishing to see whether "launch" or similar in Rev had additional depth or granularity to keep an eye on the application it launch-ed. From what you say the answer to that is no, unless you implement a solution with sockets.

Thanks again Mark,

Kind regards, Andrew

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Oct 24, 2009 2:19 am

That's a nice solution, Andrew.

And no, the launch command doesn't provide any status check on the processes it opens.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

hliljegren
Posts: 111
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Post by hliljegren » Sun Oct 25, 2009 3:57 pm

Shouldn't it be possible to at least get the process id and then maybe watch that?

A long time ago ... in a galaxy far away. Well at least in a totally different programming language I used stderr for outputting status back to my main process. I know it's not what stderr is supposed to be used for but it worked for my purpose...

But if you already write your status to a database I think you should be at home.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Oct 25, 2009 4:00 pm

hliljegren,

Revolution won't read from stdout and stderr until the process has finished compeltely. So, that won't work.

Yes, it is definitely possible to poll the process until the process is no longer alive.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 115
Joined: Wed Apr 08, 2009 11:54 pm

Launch - Houston, we have a problem

Post by dickey » Sun Oct 25, 2009 11:48 pm

Thanks hlilegren and Mark for your replies.

The database approach is working well.

I have been spawning (with launch) usually between 2-8 of these processes in the time it takes Rev to execute the code, and they run simultaneously on Windows in individual command.com (cmd) windows. An enormous time saver for my purposes.

When I was experimenting with capturing the output returned by the a completed process, Rev would wait until that output was returned, before running the next launch command, which defeated the purpose launching multiple apps in a near simultaneous fashion.

The other problem was of course the output itself. I know I can hide the cmd windows, but chose to leave them open to watch the show. I was experimenting, and decided to close at a window I had launched from Rev whilst it was still executing. The output Rev reported was
OK
which perhaps says more about the state of the window (closed OK), rather than the underlying process, which had just been bombed. I decided that reliance on messages returned by launch might be a little misguided under these circumstances.

Thanks again for posting replies.

Kind regards, Andrew

BattleWolf
Posts: 5
Joined: Wed Oct 21, 2009 3:53 am

Post by BattleWolf » Sun Nov 01, 2009 12:08 pm

How about using the presence of a (temporary and empty?) file as a status check as opposed to the content of such a file? In theory this should prevent the simultaneous access issues...

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 115
Joined: Wed Apr 08, 2009 11:54 pm

Launch - Houston, we have a problem

Post by dickey » Mon Nov 02, 2009 1:24 pm

Thank you for posting BattleWolf...

Post Reply