Created
December 5, 2024 00:55
-
-
Save changx03/85ed52f320d139ab58c5bf09f01762ce to your computer and use it in GitHub Desktop.
Using Python subprocess to run ping command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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