-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process: Add combined mode with TTY for input and PTY for output #40037
Comments
Ah, I forgot to mention an alternative approach. Another idea was to use the PTY mode and to pass an input stream to the process and once the bash script expects an user input I use the
Maybe this is working somehow but I did not find a solution for it? |
Yes, it is wrong :) Each process has three file descriptors open by default: stdin, stdout, and stderr. When you run a program from a terminal and you wish to spawn another process and let it read&write from the terminal to communicate with the user, you need to pass the three file descriptors to it. The parent process gets the file descriptors connected to the terminal and the child process inherits the same file descriptors so that it can access the terminal too. In your solution, you open /dev/tty again; therefore, you establish a new connection to the terminal rather than using the original input. If you try to redirect input to your program, it will still wait for the user input, e.g., The allocation of PTY allows programs to perform more advanced oprations with the terminal. Not sure about the details here, but you should not need it as long as you only use some colors and other basic stuff. The correct solution should be to pass Take a look at http://docs.php.net/manual/en/function.posix-isatty.php. Try make a little script that shows three booleans (one the three file descriptors) so that you know that you connected them correctly. All three should be true if you simply run the command from a terminal; they should be false when redirected to/from a file. |
@jkufner Thanks for your reply! You are right, passing |
Thank you for this issue. |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Description
I am not very deep in this topic, but I played around with the Symfony
Process
andConsole
components. My idea was to create a command that executes a bash script and then reads the output of the bash script and writes it in a better style to the console again. That was not even hard to achieve. Here is an example where the output is written with the "text" function to the console:The next thing I tried was to also make that work with interactive scripts. The first problem was that the "read" within my bash script was skipped by the process. I found out that if I use
$process->setPty(true)
the "read" is not skipped and that the command waits for an input. But now the problem was that after typing something to the console nothing happened. Then I found out, that if I use$process->setTty(true)
the command waits for an input and when I type something to the console that was also applied to the script and the script continued with execution. But now the problem was that I could not change the style of the output anymore, because you cant access the output in TTY mode.So I needed a combination of both modes. TTY for input and PTY for output. So I just tried to return the following array in the
getDescriptors
function of theSymfony\Component\Process\Pipes\UnixPipes
class:And voila, now my command was actually working as expected. The output was printed in the "text" style and once the script came to the "read" part, the script waited for user input and after I typed it to the console, the script continued the execution with my user input.
Like I said, I'm not really deep in this topic. "PTY" and "TTY" are terms I have never heard before. So I don't know if that makes sense, but if so, is it possible to implement this combined method for the
Process
component?The text was updated successfully, but these errors were encountered: