2

When i did something in Python as:

ping = subprocess.Popen("ping -n 1 %s" %ip, stdout=subprocess.PIPE)

it is always to print out to screen:

(subprocess.Popen object at 0x.... )

It's a bit annoying for me. Do you know how to avoid that std output ?

jfs
  • 399,953
  • 195
  • 994
  • 1,670
SieuTruc
  • 475
  • 1
  • 7
  • 16

1 Answers1

2

It looks like you're trying to get the stdout from the process by printing the ping variable in your example. That is incorrect usage of subprocess.Popen objects. In order to correctly use subprocess.Popen this is what you would write:

ping_process = subprocess.Popen(['ping', '-c', '1', ip], stdout=subprocess.PIPE)

# This will block until ping exits
stdout = ping_process.stdout.read()
print stdout

I also changed the arguments you used for ping because -n is an invalid argument on my machines implementation.

ravenac95
  • 3,557
  • 1
  • 20
  • 21