Skip to content

Instantly share code, notes, and snippets.

@changx03
Created December 5, 2024 00:55
Show Gist options
  • Save changx03/85ed52f320d139ab58c5bf09f01762ce to your computer and use it in GitHub Desktop.
Save changx03/85ed52f320d139ab58c5bf09f01762ce to your computer and use it in GitHub Desktop.
Using Python subprocess to run ping command
import subprocess
# Using Popen for a long-running process or custom interaction
process = subprocess.Popen(
["ping", "www.google.com"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
shell=True,
)
for line in process.stdout:
print(line, end="") # Print the output line by line in real-time
process.wait() # Wait for the command to complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment