[fpc-pascal] Re: a few AssignStream questions

Seth Grover sethdgrover at gmail.com
Mon Jul 27 15:27:50 CEST 2009


I actually figured out the answer to both my questions, which I'll
post here in case somebody is ever searching these archives and has
the same question:

Immediately after calling AssignStream and getting the resultant PID,
you can do something like this:

// check to see if the PID has already exited
if (fpWaitPid(pid,pcint(@exitCode),WNOHANG) = pid) then begin
  // a 127 exit code indicates "command not found
  if (wexitstatus(exitCode) = 127) then begin
    raise Exception.Create('PipelineClass.Create: Command not found in PATH');
  end;
end;

Apparently the exit code "127" has a special meaning indicating that
the command was not found.

-SG

--
This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.

Seth Grover
sethdgrover[at]gmail[dot]com



On Mon, Jul 27, 2009 at 6:07 AM, Seth Grover<sethdgrover at gmail.com> wrote:
> http://community.freepascal.org:10000/docs-html/rtl/unix/assignstream.html
>
> A few questions about AssignStream:
>
> 1. I can't seem to figure out a way to see if the program I ran
> actually executed. For example, if I pass in something bogus for the
> Prog parameter (some filename that doesn't even exist), I still get a
> PID back. It's just that the PID is in a defunct (zombie) state. I
> could read the status file in /proc/ for that PID, but that seems
> rather a waste to do with each program I execute via AssignStream.
>
> 2. Is there a way for me to get the exit code of a program executed
> with AssignStream?
>
> Thanks,
>
> Seth
>
> --
> This email is fiction. Any resemblance to actual events
> or persons living or dead is purely coincidental.
>
> Seth Grover
> sethdgrover[at]gmail[dot]com
>



More information about the fpc-pascal mailing list