Rdemps Rdemps - 8 months ago 39
Python Question

Python subprocess command to run echo and leave the window open

in python 2.7, I'm trying to:

  1. Ping an IP address with a subprocess command without showing a console window.

  2. If the ping subproccess command returns anything other than 0, alert the user that the ping failed

  3. alert the user using an echo command via a subproccess

Steps 1 and 2 are done. I am having problems with step 3. If there is a better way to do this than what I'm trying to do, I'm open to suggestions. I just wanted a quick and easy way to display a short warning to the user.

The big issue with step 3 is the console window appears, but disappears very quickly. Ideally I'd like to leave the window open until some user feedback is received, but at this point I'll take a timeout too.

Here is what I have:

subprocess.call(['echo', 'One or more of the IPs failed to respond to their ping. Check Logs', ' & pause'])

The end result I'm looking for is the user is going about their daily business on their PC, a popup occurs that tells them a planned ping attempt did not reach its destination, the user provides feedback to close the popup.

Ni. Ni.

In a windows enviroment:

def cmdMessage(message):
    subprocess.call('cmd /K "echo ' + message + '"')

cmdMessage('One or more of the IPs failed to respond to their ping. Check Logs')