partben partben - 2 years ago 119
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)

Answer Source

Just put them together:

os.system("net view /all; ping -n 6 > nul")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download