Re: managing output from my programs

Scott Raney ((no email))
Thu, 10 Feb 94 16:34:28 MST

>
> Hi again all,
>
> I'm working on small "front-end" stack for a computation program which takes
> around one hour to execute. I had problems with the colors, it is solved,
> I used: set colors of stack "my mainstack" to colors of stack "Home" and it
> worked fine.
>
> Now I'm having problems getting the output of my program where and when I
> want to. Here'e an excerpt of the script for the "OK" button:
>
> on mouseUp
> ...
> lock screen
> show field "echo"
> unlock screen
> put shell("echo $HOME\\c") into homd
> put "(" & homd & "/bin/solve -n 15 -d" && field "debit" && "-p" && field "angle" && \
> "-w" && field "omega" && ") 2> erreurs" into goforit

There are two problem here. The first is that the () are useless:
open process does *not* run a shell (that's what the shell() function
does). The second is that the redirection also won't work, since a
shell isn't executed. If you really need a shell, you'll have to use
open process to open a /bin/sh process, and then write your commands
to *that*.

> open process goforit for read
> repeat forever
> read from process goforit for 1 line
> if it is empty then
> close process goforit
> exit repeat
> else put it after field "echo"
> end repeat
> beep 2
> ...
> end mouseUp
>
> This is very similar to the "OK" button of the "Sample Files Dialog" stack.
> However the command:
>
> $HOME/bin/solve -n 15 -d "debit" -p "angle" -w "omega"
>
> takes around one hour to complete and I would like to get the stdout, which
> inform the user about the state of the computations, into the field "echo"
> along the way. This command also produce output on stderr which I would like
> to redirect to a file (erreurs). Until now I only managed to make it work
> by putting exactly the command above without redirections into goforit. I
> then get stderr into field "echo" as soon as it is produced and stdout only
> at the end of execution. What should I do?

With both shell() and open process, the stdout and the stderr will be
mixed together in what is returned from the read. If you need them
separate, you'll either have to use open process to run a shell script
which redirects one or both of them, or enhance your program so that
it takes output files as command line arguments.

Even better approaches would be to either make your program into an
external and use the callbacks to update the status, or have your
program write its status to a file and then send MetaCard a SIGUSR1
when it changes the file (you can get the engine's process id with the
"processId" function). Since MetaCard polls when reading in shell()
or from an open process (it never blocks on reads), it is wasting
valuable CPU time in your situation.

> Thanks
> Luc
> --
> marcouil@ireq.hydro.qc.ca
>
>

-- 
***********************************************************************
* Scott Raney  303-447-3936            Remember: the better you look, *
* raney@metacard.com                   the more you'll see -- Lidia   *
***********************************************************************