subprocess.Popen under windows 7
Frank van den Boom
frank at am-knie.de
Fri Dec 9 04:47:14 EST 2011
Thank you very much.
Now I have written a little c++ programm which produces some ouput.
And now it works fine.
There is something wrong with 7zip.exe and the arglist with *.
Tonight I will go on and hunt the error.
It should be Python 2.7
#!/usr/bin/env python
PATH_TO_EXE = "C:/Users/yoicks/Desktop/ausgabe.exe"
import os, shutil, sys, subprocess, traceback
try:
# win32
from msvcrt import getch
except ImportError:
# unix
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
try:
tty.setraw(fd)
return sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
def press_any_key():
print "Press any key to continue."
getch()
def exit_with_string(exit_string):
print exit_string
press_any_key()
sys.exit(exit_string)
def start_exe (PATH_TO_EXE):
try:
arglist = [PATH_TO_EXE]
print ("try running cmd:\n %s\n" % (' '.join(arglist)))
sp = subprocess.Popen(args=arglist, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
except:
print "Error while running subprocess.\n"
print "Traceback:\n%s"%traceback.format_exc()
return False
output, error = sp.communicate()
if output:
print output
if error:
print error
return False
return True
return_value = start_exe(PATH_TO_EXE)
if return_value:
print("Backup successfully written.")
else:
print("FAILURE during the backup")
press_any_key()
* Englisch - erkannt
* Englisch
* Deutsch
* Englisch
* Deutsch
<javascript:void(0);>
More information about the Python-list
mailing list