saleyn / erlexec

Execute and control OS processes from Erlang/OTP
https://hexdocs.pm/erlexec/readme.html
Other
542 stars 142 forks source link

`debug(1)` impacts stdout of a command #181

Closed kape1395 closed 2 months ago

kape1395 commented 3 months ago

While debugging #180 I found that some logging statements appear in the program's stdout instead of being logged (I have omitted the logged statements to make this more readable).

28> exec:debug(0).                                                  
29> exec:run_link("/usr/bin/echo asd", [sync, stdout, stderr, pty]).
{ok,[{stdout,[<<"asd\r\n">>]}]}

30> exec:debug(1).                                                  
31> exec:run_link("/usr/bin/echo asd", [sync, stdout, stderr, pty]).
{ok,[{stdout,[<<"TIOCSWINSZ rows=43430 cols=23527 tty=-1 ret=-1 [exec_impl.cpp:186]\r\r\nTIOCSWINSZ rows=1974839"...>>,
              <<"asd\r\n">>]}]}

Also, if the pty option is specified, stderr is returned as stdout:

49> exec:run_link("/usr/bin/echo asd; (/usr/bin/echo dsa >&2)", [sync, stdout, stderr]).     
{ok,[{stdout,[<<"asd\n">>]},{stderr,[<<"dsa\n">>]}]}
50> exec:run_link("/usr/bin/echo asd; (/usr/bin/echo dsa >&2)", [sync, stdout, stderr, pty]).
{ok,[{stdout,[<<"asd\r\n">>,<<"dsa\r\n">>]}]}

In my case that's minor, as the pty option was specified by a mistake.

saleyn commented 2 months ago

With pty the stderr is returned to stdout. This is not a bug in erlexec but a unfortunately is the limitation of the pty option related to the tty's behavior.