Hi,
How can I know whether a TProcess failed when trying to execute it ? Running will be false, but I want to distinguish between the file not there / no execution permission / etc. and it started running but was done quickly.
Micha

Mailing lists / fpc-pascal / 2006-02
11 messages · 3 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
How can I know whether a TProcess failed when trying to execute it ? Running will be false, but I want to distinguish between the file not there / no execution permission / etc. and it started running but was done quickly.
Micha
How can I know whether a TProcess failed when trying to execute it ? Running will be false, but I want to distinguish between the file not there / no execution permission / etc. and it started running but was done quickly.
Andrew suggested ExitStatus on IRC, but a process that failed executing does not have an exitstatus, does it ?
Micha
How can I know whether a TProcess failed when trying to execute it ? Running will be…
It should raise an exception if execution fails ?
Michael.
That I should have noticed :-). In unix, the return result of the 'fpexecve' call is not checked, at least. If it returns, it does 'halt(127)', so should I check the ExitStatus being 127 ?
Micha
Yes. If you look at things like "man popen" under Linux (or pretty much any *nix), you'll also see comments like this:
Failure to execute the shell is indistinguishable from the shell’s
failure to execute command, or an immediate exit of the command. The
only hint is an exit status of 127.
The reason is that because of the fork/vfork construct these OS'es use, there is no way to report an error to the parent process except by exit codes.
Jonas
But how about windows ? I see it raises an exception, so that's the origin of Michael's reply I guess. This makes TProcess non-uniform cross-platform :-(. Can it be improved ? Either have a documented 127 exitcode (for windows too), or raise an exception in unix for exitcode 127 ?
Micha
That I should have noticed :-). In unix, the return result of the 'fpexecve' call is not…
On unix, yes. I'll see if I can add some checking at the TProcess level.
Michael.
But how about windows ? I see it raises an exception, so that's the origin of Michael's…
That is what I want to do. The problem is that this is not foolproof, because you don't know when this exitcode will arrive, and waiting is not an option.
Michael.
Yes. If you look at things like "man popen" under Linux (or pretty much any *nix), you'll…
The reason is that because of the fork/vfork construct these OS'es use, there is no way to report an error to the parent process except by exit codes.
This is not true btw: you can use shared memory. Set up a variable in the parent process so the child process knows where to write what happened plus error codes. Don't know how difficult it is to do in fpc though, but I guess it's just as "simple" as in C using fpmmap and friends ?
Micha
That seems a bit excessive for error reporting.
Michael.
How can I know whether a TProcess failed when trying to execute it ? Running will be…
How can I know whether a TProcess failed when trying to execute it ?
I'm also having problems how to when the process has started or failed. I thought of trying to see whether its output handle was signalled for reading, but that doesn't work: the handle is signalled, but Process.Running is still true if I query it, while the process to be executed doesn't exist.
Any pointers on this topic are appreciated.
Micha