- Factored out the safe external command process. It turns out that the shell should not be used under windows Popen, but on the other hand is must be used under Linux.
This commit is contained in:
parent
23931281d0
commit
f47c1e7e5e
@ -9,17 +9,13 @@ import sys
|
||||
import re
|
||||
import threading
|
||||
import StringIO
|
||||
try:
|
||||
from subprocess import Popen
|
||||
AvailablePopen = True
|
||||
except:
|
||||
AvailablePopen = False
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
""" Import scyther components """
|
||||
import Scyther.Scyther
|
||||
import Scyther.Error
|
||||
from Scyther.Misc import *
|
||||
|
||||
""" Import scyther-gui components """
|
||||
import Tempfile
|
||||
@ -166,8 +162,6 @@ class AttackThread(threading.Thread):
|
||||
font = wx.Font(9,wx.SWISS,wx.NORMAL,wx.NORMAL)
|
||||
self.fontname = font.GetFaceName()
|
||||
|
||||
|
||||
|
||||
# write all graph lines but add layout modifiers
|
||||
for l in txt.splitlines():
|
||||
fp.write(l)
|
||||
@ -204,8 +198,6 @@ class AttackThread(threading.Thread):
|
||||
def makeImage(self,attack):
|
||||
""" create image for this particular attack """
|
||||
|
||||
global AvailablePopen
|
||||
|
||||
if Preference.usePIL():
|
||||
# If we have the PIL library, we can do postscript! great
|
||||
# stuff.
|
||||
@ -229,11 +221,7 @@ class AttackThread(threading.Thread):
|
||||
|
||||
# execute command
|
||||
# Start the process
|
||||
if AvailablePopen:
|
||||
p = Popen(cmd, shell=False)
|
||||
sts = p.wait()
|
||||
else:
|
||||
os.system(cmd)
|
||||
safeCommand(cmd)
|
||||
|
||||
# Print
|
||||
#print fpname2
|
||||
|
@ -5,7 +5,14 @@
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
""" Import externals """
|
||||
import sys
|
||||
import os.path
|
||||
try:
|
||||
from subprocess import Popen
|
||||
AvailablePopen = True
|
||||
except:
|
||||
import os
|
||||
AvailablePopen = False
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
@ -43,3 +50,21 @@ def mypath(file):
|
||||
basedir = os.path.dirname(__file__)
|
||||
return os.path.join(basedir,file)
|
||||
|
||||
def safeCommand(cmd):
|
||||
""" Execute a command with some arguments. Safe cross-platform
|
||||
version, I hope. """
|
||||
|
||||
global AvailablePopen
|
||||
|
||||
if AvailablePopen:
|
||||
if sys.platform.startswith("win"):
|
||||
shell=False
|
||||
else:
|
||||
shell=True
|
||||
p = Popen(cmd, shell=shell)
|
||||
sts = p.wait()
|
||||
else:
|
||||
sts = os.system(cmd)
|
||||
|
||||
return sts
|
||||
|
||||
|
@ -11,11 +11,6 @@ import os.path
|
||||
import sys
|
||||
import StringIO
|
||||
import tempfile
|
||||
try:
|
||||
from subprocess import Popen
|
||||
AvailablePopen = True
|
||||
except:
|
||||
AvailablePopen = False
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
@ -198,7 +193,6 @@ class Scyther(object):
|
||||
output -- string which is the real output
|
||||
errors -- string which captures the errors
|
||||
"""
|
||||
global AvailablePopen
|
||||
|
||||
if self.program == None:
|
||||
raise Error.NoBinaryError
|
||||
@ -233,11 +227,7 @@ class Scyther(object):
|
||||
##print self.cmd
|
||||
|
||||
# Start the process
|
||||
if AvailablePopen:
|
||||
p = Popen(self.cmd, shell=False)
|
||||
sts = p.wait()
|
||||
else:
|
||||
os.system(self.cmd)
|
||||
safeCommand(self.cmd)
|
||||
|
||||
# reseek
|
||||
fhe = os.fdopen(fde)
|
||||
|
Loading…
Reference in New Issue
Block a user