TProcess execution

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

TProcess execution

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Micha Nelissen
On Wed, 8 Feb 2006 20:30:50 +0100
Micha Nelissen <[hidden email]> 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.

Andrew suggested ExitStatus on IRC, but a process that failed executing
does not have an exitstatus, does it ?

Micha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Michael Van Canneyt
In reply to this post by Micha Nelissen


On Wed, 8 Feb 2006, Micha Nelissen wrote:

> 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.

It should raise an exception if execution fails ?

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

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

Micha

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Jonas Maebe-2

On 9 feb 2006, at 07:48, 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 ?

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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

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

Micha

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Michael Van Canneyt
In reply to this post by Micha Nelissen


On Thu, 9 Feb 2006, Micha Nelissen wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Michael Van Canneyt
In reply to this post by Micha Nelissen


On Thu, 9 Feb 2006, Micha Nelissen wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Micha Nelissen
In reply to this post by Jonas Maebe-2
On Thu, 9 Feb 2006 08:42:21 +0100
Jonas Maebe <[hidden email]> 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 ?

Micha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Michael Van Canneyt


On Thu, 9 Feb 2006, Micha Nelissen wrote:

> On Thu, 9 Feb 2006 08:42:21 +0100
> Jonas Maebe <[hidden email]> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TProcess execution

Micha Nelissen
In reply to this post by Micha Nelissen
On Wed, 8 Feb 2006 20:30:50 +0100
Micha Nelissen <[hidden email]> wrote:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal