How to wait for OS command run with $zf(-100,"/ASYNC") to finish
I'm trying to write a method that runs an OS command with $zf(-100,"/ASYNC") and then waits for it to finish before returning, but I can't figure out how to check if the child process (in $zchild) is still running. $System.Process.State($zchild) always returns "RUN" even once the child process is gone. Is there some better way to check this, short of running another OS-specific command and processing the output (which is just really annoying and unelegant)?
Comments
Hi Tim,
That's kind of a confusing question! Isn't the point of /async so that you don't wait for the process to finish? Do you need to use /async for some other reason?
What I'm trying to do is manage the process spawned with $zf(-100) from ObjectScript. In short, if the ObjectScript process is killed or <INTERRUPT>ed (which you can't do while in a ZF state), I want to kill the spawned process as well.
More specifically, I have a main ObjectScript process that's monitoring an Angular build. It spawns another ObjectScript process that used to just call $zf(-100) synchronously to run a build script. This other process would then notify the parent via $System.Event when it's done. Normally this build script will run for a finite period of time, but I'm looking to run an Angular build with the --watch flag and terminate it when the user Ctrl+C's in Terminal.
That is an interesting idea, but I don't have too much experience with zf(-100). Hope you can find some help.
I think it's probably going to just come down to using a pipe/command pipe/etc. instead of $zf(-100).
can't figure out how to check if the child process (in $zchild) is still running.
Append 2 commands to your main command.
First one, execute before your main command to create a file with a name equal to process id.
Second one, execute after your main command. It deletes the file.
In your IRIS process check if the file exists.
Ugly but it works.
I was hoping to avoid something like that. It seems like I run into other issues with what I'm trying to do though around killing the spawned process anyway. I think $zf(-100) just won't do the trick.
Perhaps the method will be useful to you: $SYSTEM.Util.CleanDeadJobs()
Problem in my case is that it's a non-IRIS process, so interactions from IRIS are limited.