partben partben - 10 months ago 41
Python Question

How to execute two cmd commands in the same instance of cmd using python

Whenever I try to do

os.system("net view /all")

with python, the code gets executed, but it instantly closes, so I can't read the output. I looked around a bit, and found that you can use

ping -n 6 > nul

to do something like


in python, but if I do

os.system("net view /all")
os.system("ping -n 6 > nul")

They are executed in different instances of cmd, one after the other, so the problem remains. How would I make them be run in the same instance, or how would I be able to put a delay after

net view /all

so that I can read the output? (Only solutions using stock python libs please)


Just put them together:

os.system("net view /all; ping -n 6 > nul")