# How to set the stderr correctly?

**URL:** <https://racket.discourse.group/t/how-to-set-the-stderr-correctly/1922>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [May 5, 2023, 11:41am UTC](https://racket.discourse.group/t/how-to-set-the-stderr-correctly/1922 "2023-05-05T11:41:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antigen-11](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/antigen-11/32/1813_2.png) [@Antigen-11](https://racket.discourse.group/u/Antigen-11)\
**Post date:** [May 5, 2023, 11:41am UTC](https://racket.discourse.group/t/how-to-set-the-stderr-correctly/1922/1 "2023-05-05T11:41:38Z")

</div>

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](https://docs.racket-lang.org/reference/subprocess.html#%28def._%28%28quote._~23~25kernel%29._subprocess%29%29).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:

```scheme
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)`?

---

<div class="post-metadata">

**Author:** ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)\
**Post date:** [May 5, 2023, 12:10pm UTC](https://racket.discourse.group/t/how-to-set-the-stderr-correctly/1922/2 "2023-05-05T12:10:01Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Antigen-11](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/antigen-11/32/1813_2.png) [@Antigen-11](https://racket.discourse.group/u/Antigen-11)\
**Post date:** [May 5, 2023, 12:21pm UTC](https://racket.discourse.group/t/how-to-set-the-stderr-correctly/1922/3 "2023-05-05T12:21:41Z")

</div>

Oh, I see 🤣  
Thanks a lot!
