I discovered os.system commands structure but I couldn’t figure out a way to keep it “alive” long enough for the SCP transfer to complete before moving on to the next steps. As a Python noob, I was having difficulty making sense of the documentation for Subprocess. This video was very useful in helping me to create a Python Script to update Rommon and iOS via SCP on my Cisco network devices. Thank you so much!
Hi sir, is it possible to input automatically to a query returned from running a command using subprocess : eg When pushing code to gihub it prompts one to input his credentials.. how can i autopupulate the response ? Thank you.
Great Video that explains subprocess module very clearly ! I have an issue where , I need to have direct interaction with a child's stdin and stdout, I should be able to capture the output of my 1st stdout , and pass it as my input to the next stdin. Below is a simple example, but I need to do this on some complex commands where the output of one command is the input to the next command. When I assign the stdout to a variable( # below), then it enters deadlock. I can issue multiple stdin's and get them working, but I need to be able to capture stdout ( manipulate) and pass it to subsequent stdin, which is where I have the issue. Any help is much appreciated. proc = subprocess.Popen(['python', '-i'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.stdin.write(b'2+2 ') proc.stdin.flush() print(proc.stdout.readline()) #out=proc.stdout.readline() proc.stdin.write(b'out+2 ') proc.stdin.flush() print(proc.stdout.readline()) proc.stdin.close() proc.terminate() proc.wait(timeout=0.2)
I have a Python / Operating system question.. In windows, I can plot a file using type logfile | cantools plot inputfile.dbc I'd like to do the same using Python. I understand everyone uses Popen, but I have not been able to get it to Pipe the contents of logfile over to cantools (while also passing the Plot and filename arguments). The following did not work: args = ["plot inputfile.dbc"] p = Popen(['cantools'] + args, stdout=PIPE) Any suggestions?