0

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 127.0.0.1 -n 6 > nul

to do something like

time.sleep()

in python, but if I do

os.system("net view /all")
os.system("ping 127.0.0.1 -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)

partben
  • 25
  • 9

3 Answers3

0

I think your question boils down to what shell is getting called when you call os.system() and how it would let you run two commands in sequence. If you're using bash, this would look like

os.system("net view /all; sleep 5")

for, e.g., a 5 second wait after the command executed.

Under Windows, this answer appears to meet your needs.

Community
  • 1
  • 1
matmat
  • 875
  • 8
  • 11
0

Just put them together:

os.system("net view /all & ping 127.0.0.1 -n 6 > nul")
Filipe Amaral
  • 1,683
  • 1
  • 14
  • 15
0

I just had to add a "&" between the two commands, so now it looks like

os.system("net view /all & ping 127.0.0.1 -n 6 > nul")
partben
  • 25
  • 9