At Sat, 8 Feb 2020 17:08:18 +0100, Bertrand Augereau wrote:
> > I'm not sure I completely understand the problem.  You're correct that
> > there's no way to tell whether the value is an exit code from the program
> > or an error from the operating system ... but there also is no way to tell
> > that starting the program from the shell  IF  you rely solely on the exit
> > code.
> >
> 
> That's why CreateProcess and fork/exec return code.

Currently, if fork() fails on Unix (e.g., because there are too many
processes), then `subprocess` will raise an exception. But if fork()
succeeds, then there's normally no way to communicate an error from
exec() except through the exit code, since exec() is in the child
process.[*] So, that's why there's no way to distinguish "program
couldn't start" from "program exited with a non-0 status" on Unix.

You're right that `subprocess` could make a distinction on Windows with
CreateProcess(). Currently, `subprocess` doesn't make a distinction,
mostly because not doing so makes the behavior somewhat more consistent
with conventional Unix behavior.

[*] It seems possible to set up an extra channel of communication to
    report whether exec() succeeds. I think that would be tricky at
    best, though, because it's not clear how to clean up the channel if
    exec() does succeed.

> > But if the idea is to tell whether the program started correctly - even if
> > it since has ended - then something like:
> >
> > (or
> >   (eq? 'running (subprocess-status ps))
> >   (not (= 0 (subprocess-pid ps)))
> >   )
> >
> > should do the trick.
> >
> 
> Yes in practice, it might be good enough.

I agree that this is not a good choice.

For compatibility while also exposing the result of CreateProcess() on
Windows, a new `subprocess-...` operation is probably best. I'll look
into adding that.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5e3ee1d3.1c69fb81.fc262.2f8aSMTPIN_ADDED_MISSING%40gmr-mx.google.com.

Reply via email to