Re: open process

Scott Raney (raney@metacard.com)
Thu, 17 Jul 1997 17:02:26 -0600 (MDT)

On Thu, 17 Jul 1997, Simon Lord wrote:

> I need an actual sample of the "open process" command. I keep trying
> but I think I'm missing the point here, I need to run a process in a
> shell but not have that process hog MetaCard until it's complete.
>
> Please give me an actual xTalk example using something like "confirm".
>
> IE., for the sake of argument, lets say I want to send someone the IRIX
> command "confirm" using MetaCard. It would look something like this:
>
> > put shell("setenv DISPLAY viper:0;confirm -b \
> > Cancel -b OK -t "&quote&"Do you eat at McSpews?"&quote&" \
> > -i question &"&";time") into tResponce
>
> This is a simple app but imagine the twit on the other end not answering
> it, MetaCard would wait all day!
>
> In the event that I may embarass myself, I will refrain from posting
> what I thought should work.

There are several issues here, most of which are specific to your
application and not shell()/open process. First, you've got three
commands there, and open process will only let you run one (of course
you could always open /bin/sh as the command and then write statements
to it, but that's more complicated). Second you should probably use
the -display option to the confirm command instead of setting the
environment variable (and hope that the twit on the other end is using
an SGI because "confirm" is one of those hyprid X/GL application that
crashes and burns when you try to run it to any non-SGI display).

The next issue is the "time" command, which won't work very well when
run asynchronously with open process. The final issue is that in 2.1,
quoted arguments aren't passed correctly (they're passed as individual
word). This is fixed in 2.1.1Bx.

So, what you want is something like the following. Instead of
"confirm", I've use the uglier but more portable xmessage. You could
also do this by building a MetaCard stack that asks the question, and
writes the response to stdout. I've also used the "format" function
instead of lots of "quote" constants:

local twitcommand, twittime
on mouseUp
put format("xmessage -display x:0 \"message\" -buttons \"yes,no\" -print") \
into twitcommand
open process twitcommand for read
put the seconds into twittime
send checkprocess to me in 1 second # or whatever interval you want
end mouseUp

on checkprocess
read from process twitcommand until empty
if it is not empty then
close process twitcommand
delete last char of it # whack trailing return
put "answer was" && it & ", time was" && the seconds - twittime
else send checkprocess to me in 1 second
end checkprocess

Note that the "close process" command isn't really necessary in this
example because xmessage (and confirm) exit after writing a single
response and so will close by themselves.

> Cheers,
> Simon
>
> --
> [---------------------------------] Simon Lord
> [No matter how idiot proof you try] Database Engineer, CAE Electronics
> [to make any product, there will ] tel: (514) 341-2000 x3861
> [always be two people somewhere in] fax: (514) 340-5496
> [the world working hard at making ]
> [a bigger and better idiot. ]
> [---------------------------------] email: simonl@cae.ca
>
> ----------------------------------------------------------------------
> Arthur C. Clarke was quoted as saying he would prefer HAL, a super-
> computer named after the famous rogue intelligence in 2001 being
> constructed at the University of Illinois, to speak these as its first
> words:
>
> "Good morning doctors. I have taken the liberty of removing Windows 95
> from my hard drive".
> ----------------------------------------------------------------------
>

***************************************************************
Scott Raney raney@metacard.com http://www.metacard.com
Any sufficiently advanced technology
is virtually indistinguishable from magic -- Clarke's law