- 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:
Cas Cremers 2007-05-19 15:32:58 +02:00
parent 23931281d0
commit f47c1e7e5e
3 changed files with 28 additions and 25 deletions

View File

@ -9,17 +9,13 @@ import sys
import re import re
import threading import threading
import StringIO import StringIO
try:
from subprocess import Popen
AvailablePopen = True
except:
AvailablePopen = False
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
""" Import scyther components """ """ Import scyther components """
import Scyther.Scyther import Scyther.Scyther
import Scyther.Error import Scyther.Error
from Scyther.Misc import *
""" Import scyther-gui components """ """ Import scyther-gui components """
import Tempfile import Tempfile
@ -166,8 +162,6 @@ class AttackThread(threading.Thread):
font = wx.Font(9,wx.SWISS,wx.NORMAL,wx.NORMAL) font = wx.Font(9,wx.SWISS,wx.NORMAL,wx.NORMAL)
self.fontname = font.GetFaceName() self.fontname = font.GetFaceName()
# write all graph lines but add layout modifiers # write all graph lines but add layout modifiers
for l in txt.splitlines(): for l in txt.splitlines():
fp.write(l) fp.write(l)
@ -204,8 +198,6 @@ class AttackThread(threading.Thread):
def makeImage(self,attack): def makeImage(self,attack):
""" create image for this particular attack """ """ create image for this particular attack """
global AvailablePopen
if Preference.usePIL(): if Preference.usePIL():
# If we have the PIL library, we can do postscript! great # If we have the PIL library, we can do postscript! great
# stuff. # stuff.
@ -229,11 +221,7 @@ class AttackThread(threading.Thread):
# execute command # execute command
# Start the process # Start the process
if AvailablePopen: safeCommand(cmd)
p = Popen(cmd, shell=False)
sts = p.wait()
else:
os.system(cmd)
# Print # Print
#print fpname2 #print fpname2

View File

@ -5,7 +5,14 @@
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
""" Import externals """ """ Import externals """
import sys
import os.path 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__) basedir = os.path.dirname(__file__)
return os.path.join(basedir,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

View File

@ -11,11 +11,6 @@ import os.path
import sys import sys
import StringIO import StringIO
import tempfile 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 output -- string which is the real output
errors -- string which captures the errors errors -- string which captures the errors
""" """
global AvailablePopen
if self.program == None: if self.program == None:
raise Error.NoBinaryError raise Error.NoBinaryError
@ -233,11 +227,7 @@ class Scyther(object):
##print self.cmd ##print self.cmd
# Start the process # Start the process
if AvailablePopen: safeCommand(self.cmd)
p = Popen(self.cmd, shell=False)
sts = p.wait()
else:
os.system(self.cmd)
# reseek # reseek
fhe = os.fdopen(fde) fhe = os.fdopen(fde)