I want to open two terminals and provide some commands in both the terminals.
Now I am not able to provide any input in any of the terminals.
process.stdin.write() is not working
Please help me out
That will append the output of the first command to the second command. Untested because I donât use Windows, so donât know if using the output of ipconfig as an argument to dir makes sense.
Please try to explain what youâre looking to accomplish here. It makes no sense to pipe the output of âipconfig.exeâ into the standard input of a shell. The output from âipconfig.exeâ is the current IP configuration, not a set of commands to execute.
At a technical level, I can tell you that the CMD shell relies on implicit inheritance of the standard handles (i.e. stdin, stdout, stderr). However, its internal start command (if executed without the /b option) uses the process creation flag CREATE_NEW_CONSOLE. The only way to inherit a set of standard handles to a new console session is to do so explicitly via the process STARTUPINFO record, as subprocess.Popen does. Therefore, instead of using shell=True to execute CMDâs start command, use creationflags=subprocess.CREATE_NEW_CONSOLE and shell=False.
The above code is just an example I gave i.e. I want to open two terminals and provide some sequence of commands in each of the terminals.
The actual problem statement is as below:
Open a terminal (terminal A) in windows. In that terminal provide ssh command to connect to another system. Once you get connected to that system, provide some series of commands to run a script.
Again open one more terminal and get connected to the same system and perform some more ssh commands.
To achieve this I am trying subprocess, I have different creationflags like CREATE_NEW_CONSOLE and DETACHED_PROCESS, after the terminal opens i am not able to provide any inputs on that terminal by process.stdin(). Nothing is getting typed in the terminal.
Using pipes for standard I/O may not work to interactively drive an ssh session. The ssh program may fully buffer its output when writing to a pipe. In this case the output from a command wonât be written to the pipe until the buffer is full. The size of the buffer is typically 1-8 KiB. The ssh program may have a command-line option to disable buffering. Also, standard input is usually line buffered, so make sure to end a command with a line feed ("\n").
If this worked, it wouldnât generally require a new console session, so I still donât see why you would need CREATE_NEW_CONSOLE.