How to set the stderr correctly?

According to the racket reference,

When provided as a port, stdout is used for the launched process’s standard output, stdin is used for the process’s standard input, and stderr is used for the process’s standard error. All provided ports must be file-stream ports. Any of the ports can be #f, in which case a system pipe is created and returned by subprocess.The stderr argument can be 'stdout, in which case the same file-stream port or system pipe that is supplied as standard output is also used for standard error.

So I typed these codes in the REPL and got errors due to the problem of permission:

Welcome to Racket v8.8.0.8 [cs].
> (define-values (sp1 stdout1 stdin1 stderr1) (subprocess (current-output-port) (current-input-port) #f #f "racket"))
> (define-values (sp2 stdout2 stdin2 stderr2) (subprocess (current-output-port) (current-input-port) (current-error-port) #f "racket"))
> exec failed (权限不够; errno=13)
> (define-values (sp3 stdout3 stdin3 stderr3) (subprocess (current-output-port) (current-input-port) 'stdout #f "racket"))
> exec failed (权限不够; errno=13)

Could someone tell me what happened here? And what can I do to set the stderr of a subprocess to the (current-error-port)?

An English translation of the error message would be useful, but one thing I see:

The path needs to be an absolute one, not relative, or you'll get an error. Use (find-executable-path "racket") to resolve it.

(You are setting the subprocess's standard error; that's what's giving you the error messages about exec failing in the second and third tries; if you read from stderr1 from the first you'll get that message too)

1 Like

Oh, I see :rofl:
Thanks a lot!