I want to send multiple commands to a shell program depends on the output.
But I can not figure out how to send multiple commands.
Python ver 3.6.8
Windows 10
Base on the reference, but my code is not workring, it only print the "ipconig", the "dir" is not working and raising error.
Error:
But I can not figure out how to send multiple commands.
Python ver 3.6.8
Windows 10
Base on the reference, but my code is not workring, it only print the "ipconig", the "dir" is not working and raising error.
1 2 3 4 5 6 7 8 9 10 |
from subprocess import Popen, PIPE process = Popen( "ipconfig" , stdin = PIPE, stdout = PIPE, shell = True , cwd = "d:" ) print ( repr (process.stdout.read())) process.stdin.flush() process.stdin.write(b 'dir\n' ) print ( repr (process.stdout.read())) process.stdin.flush() process.stdin.write(b 'tasklist\n' ) print ( repr (process.stdout.read())) |
Quote:Traceback (most recent call last):
File "d:\Inbox\Desktop\delete m2e.py", line 8, in <module>
process.stdin.flush()
OSError: Errno 22 Invalid argument