On 2/8/2020 3:37 AM, Bertrand Augereau wrote:
:
I spawn my subprocess with subprocess :
https://docs.racket-lang.org/reference/subprocess.html
And for the sake of completeness I want to know when suprocess failed
(because the users tampered with the exe, because there's an ACL
issue, whatever).
The function doesn't have a return value for failure and it doesn't
raise an exception when I do stuff like
(subprocess "no exe here")
or
(subprocess "nice picture of an aardvark.png")
It only returns a seemingly valid value.
The 1st value returned by (subprocess) is an opaque reference to the
executing process. If you pass the reference to (subprocess-status) it
will return *'running* if the process currently is executing, or the
exit/error value.
Can someone help me ? Is it an API defect and a special value should
be returned ? Should an exception be raised ? The doc doesn't say much
about this.
A special value is returned - the opaque reference. Perhaps the docs
could use a simple example of how to use the functions effectively. Try
playing a bit with the following:
#lang racket
(define sub #f)
(let [
(name "C:\\WINDOWS\\system32\\notepad.exe")
(in #f)(out #f)(err #f)
]
(set!-values (sub out in err) (subprocess #f #f #f name))
)
(subprocess-status sub)
(subprocess-pid sub)
(subprocess-wait sub)
;; close subprogram here
(subprocess-status sub)
(subprocess-pid sub)
I don't really care about the OS-level cause of the failure but I need
to know if it failed.
I didn't test on my Linux box for consistency.
By the way, subprocess-pid returns 0 on such a "never spawned"
process, and I think it should be an error case too.
No actual process can have pid 0 ... that value is reserved (on
Unix/Linux and Windows).
Racket doesn't support fork (because Windows doesn't), but recall that
when you fork in Unix/Linux, the child process receives the illegal pid
value 0 so that it knows it is the child, while the parent receives the
real pid value for the child.
Also note that (subprocess-pid) will be valid only if the process
started successfully.
Hope this helps,
George
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/447df58e-66ba-49aa-8151-7a8abd943090%40comcast.net.