saleyn / erlexec

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

Cannot disable pty echo: Inappropriate ioctl for device #38

Closed dsabanin closed 10 years ago

dsabanin commented 10 years ago

First of all, thanks for the awesome library! You really covered a lot of use cases and I'm really enjoying how it works. I'm having a minor issue, but the overall experience is great. Thanks for the docs too!

I'm trying to enable PTY mode, but for some reason it doesn't work with the following error:

Cannot disable pty echo: Inappropriate ioctl for device

What could be the reason for this? Am I doing something wrong? Thanks!

Code excerpt:

OutputHandler = fun (Stream, OsPid, Data) -> ... end,
exec:run(SetupCmd, [sync, pty, {kill_timeout, ?SETUP_TIMEOUT},
                               {stdout, OutputHandler},
                               {stderr, OutputHandler}]).

Just in case it matters, Erlang VM (R17) is running in VirtualBox VM under Mac OS X. The command I executes starts a docker container.

saleyn commented 10 years ago

Quite frankly, the pty support was suggested and contributed by another user, and while it works on Linux, I haven't tested it on Mac, as I don't have access to MacOS X. Likely pty is handled a bit differently there, and you can troubleshoot the issue by checking if this https://github.com/saleyn/erlexec/blob/master/c_src/exec.cpp#L1134 function call is supposed to work on Mac.

dsabanin commented 10 years ago

Sorry for the misunderstanding, Erlang is running inside VirtualBox VM that runs Ubuntu, so it fails on Linux.

Thanks for getting back to me! I'll try to update this issue if I figure it out.

dsabanin commented 10 years ago

After some experiments, it turned out that the PTY mode works perfectly if the code doesn't attempt to disable ECHO mode.

In my case, I do not care about ECHO mode, so I'm not sure if it's correct to deny PTY mode completely in case if disabling ECHO fails. Certainly not in my case. Would it make sense to just ignore the failure to disable ECHO mode and continue setting up the PTY?

Thanks!

saleyn commented 10 years ago

What is the OS error that you are getting when there's a failure to disable echo?

dsabanin commented 10 years ago

"Inappropriate ioctl for device"

saleyn commented 10 years ago

I think it should be safe to ignore the error. What the error means is that the standard input is not a terminal, and it can't echo there anyway. See: http://unix.stackexchange.com/questions/82658/bash-script-error-stty-standard-input-inappropriate-ioctl-for-device

I'll commit the fix.

dsabanin commented 10 years ago

Thank you!