diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index 48879e0..fb10a33 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -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 diff --git a/gui/Scyther/Misc.py b/gui/Scyther/Misc.py index 4346491..1a1a212 100644 --- a/gui/Scyther/Misc.py +++ b/gui/Scyther/Misc.py @@ -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 + diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 736a0f2..a29c2d6 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -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)