Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-02

TProcess execution

11 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Micha Nelissen

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

Reply by email

Micha Nelissen
to Micha Nelissen
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

Reply by email

Micha Nelissen
to Michael Van Canneyt
Michael Van Canneyt wrote 9 lines
On Wed, 8 Feb 2006, Micha Nelissen wrote: > 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. It should raise an exception if execution fails ?

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

Reply by email

Jonas Maebe
to Micha Nelissen
Micha Nelissen wrote 11 lines
>> 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. > It should raise an exception if execution fails ? 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 ?

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

Reply by email

Micha Nelissen
to Jonas Maebe
Jonas Maebe wrote 10 lines
On 9 feb 2006, at 07:48, Micha Nelissen wrote: > 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 ? 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.

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

Reply by email

Michael Van Canneyt
to Micha Nelissen: That I should have noticed :-). In unix, the return result of the 'fpexecve' call is not…
Micha Nelissen wrote 15 lines
Michael Van Canneyt wrote: > > On Wed, 8 Feb 2006, Micha Nelissen wrote: > > > 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. > > It should raise an exception if execution fails ? 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 ?

On unix, yes. I'll see if I can add some checking at the TProcess level.

Michael.

Reply by email

Michael Van Canneyt
to Micha Nelissen: But how about windows ? I see it raises an exception, so that's the origin of Michael's…
Micha Nelissen wrote 16 lines
Jonas Maebe wrote: > > On 9 feb 2006, at 07:48, Micha Nelissen wrote: > > > 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 ? > > 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. 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 ?

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.

Reply by email

Micha Nelissen
to Jonas Maebe: 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

Reply by email

Michael Van Canneyt
to Micha Nelissen
Micha Nelissen wrote 11 lines
On Thu, 9 Feb 2006 08:42:21 +0100 Jonas Maebe wrote: > 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 ?

That seems a bit excessive for error reporting.

Michael.

Reply by email

Micha Nelissen
to Micha Nelissen: 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

Reply by email