How to use "open process" for read and write?

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

How to use "open process" for read and write?

Post by Garrett » Sat Apr 08, 2006 10:29 pm

Using Rev 2.6.1 on OS X

Greetings,

How do you properly syntax the open process command? I want to
read and write to the process. I tried the following:

Code: Select all

open process "/usr/bin/apphere" for read,write
But get this error "Handler: bad command" So I tried this:

Code: Select all

open process "/usr/bin/apphere" for read write
But get this error "Expression: missing factor" So I'm not sure how to
format the code correctly.

Any help, hints or suggestions is appreciated. Thanks,
-Garrett

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Sat Apr 08, 2006 10:55 pm

you should have tried:

Code: Select all

open process "/usr/bin/apphere" for update
The documentation is a bit confusing at first but the string at the top of each entry means:

open process appName [for [text|binary] {read | write | update | neither}]
open process (optional 1) for (optional 2) text or binary (end of optional 2) (one of these) read or write or update or neither (end of one of these) (end of optional 1)
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Sat Apr 08, 2006 11:22 pm

Ahhhhhh...... Ok, I understand now.

Yeah, the example in the docs didn't really convey the possible uses.

Thanks a bunch! :-)
-Garrett

pevensen
Posts: 21
Joined: Mon Apr 10, 2006 2:50 pm
Location: St. Louis, MO, USA
Contact:

How to use "open process" for read and write?

Post by pevensen » Wed Apr 12, 2006 5:07 pm

This is a related question. On Windows and Mac, what exactly does read from process and write to process do?

Does it read the stdout of the process and write to the stdin?

Does this mean that the launched app needs to use the stdio library?

I can see in a Unix context, this is how it would work, but with an OS X or Windows app, this seems a bit strange.
Peter Evensen
[url]http://www.PetersRoadtoHealth.com[/url]

36degrees
Livecode Staff Member
Livecode Staff Member
Posts: 5
Joined: Mon Apr 10, 2006 12:03 pm

Post by 36degrees » Wed Apr 12, 2006 7:06 pm

They do as you would expect :)

In the case of OS X, since it is based on BSD UNIX, all applications implicitly have a stdin/stdout/stderr triplet just like on other Unices so it uses them. Of course, whether or not the application uses them is another matter. The OS X Console utility gives a GUI to see the output of any running applications.

You can also compile applications on OS X as UNIX processes - and these don't have the application bundle structure. As I recall, originally you couldn't call this style of process from Revolution on OS X - but I believe this was fixed in 2.6.1.

In the case of Windows, you can compile executables in either Console mode or GUI mode. The former is provided with the standard i/o handles by the OS, while the latter has to request them.
Mark Waddingham
Director of Technology
Runtime Revolution, Ltd

pevensen
Posts: 21
Joined: Mon Apr 10, 2006 2:50 pm
Location: St. Louis, MO, USA
Contact:

Post by pevensen » Wed Apr 12, 2006 7:50 pm

36degrees wrote:They do as you would expect :)
Now the big question is how about Java? Could you use it to pass data to a Java app?

I guess my original question was also what was needed for the launched process to receive data written to it and output data that is read. I think you confirmed that it uses stdio (stdin and stdout).

Thanks!
Peter Evensen
[url]http://www.PetersRoadtoHealth.com[/url]

36degrees
Livecode Staff Member
Livecode Staff Member
Posts: 5
Joined: Mon Apr 10, 2006 12:03 pm

Post by 36degrees » Thu Apr 13, 2006 4:52 pm

The answer is: yes it could...

As I recall (although my memory might be faulty, its been a while since I wrote anything Java) the Java class library gives you access to the stdio/stdin/stderr handles through some static methods of the System class.

If the Java app is written to use those, then using open process on the java app (invoked using the appropriate command line arguments passed to the JVM) should work as you would like.
Mark Waddingham
Director of Technology
Runtime Revolution, Ltd

Post Reply

Return to “Talking LiveCode”