From 8f1e1ae8a94cec7e73efba8dbc1b6b4a4b202d1f Mon Sep 17 00:00:00 2001 From: ccremers Date: Thu, 14 Dec 2006 20:08:34 +0000 Subject: [PATCH] - Complete rewrite of Scyther call (also preparing for Mac OS X versions) --- gui/Scyther/Scyther.py | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 8b7c435..4085991 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -166,28 +166,42 @@ class Scyther(object): if self.program == None: raise Error.NoBinaryError - # Generate a temproary file for the error output - errorfile = tempfile.NamedTemporaryFile() + # Generate temporary files for the output + # Requires Python 2.3 though. + (fde,fne) = tempfile.mkstemp() # errors + (fdo,fno) = tempfile.mkstemp() # output + (fdi,fni) = tempfile.mkstemp() # input + + # Write (input) file + fhi = os.fdopen(fdi,'w+b') + if spdl: + fhi.write(spdl) + fhi.close() # Generate command line for the Scyther process self.cmd = "" self.cmd += "\"%s\"" % self.program - self.cmd += " --append-errors=%s" % (errorfile.name) + self.cmd += " --append-errors=%s" % fne + self.cmd += " --append-output=%s" % fno self.cmd += " %s %s" % (self.options, args) + if spdl: + self.cmd += " %s" % fni - # Start the process, push input, get output - (stdin,stdout) = os.popen2(self.cmd) - if self.spdl: - stdin.write(self.spdl) - stdin.close() - output = stdout.read() - stdout.close() + # Start the process + os.system(self.cmd) - # get errors - self.errors = [] - errorfile.seek(0) - errors = errorfile.read() - errorfile.close() + # reseek + fhe = os.fdopen(fde) + fho = os.fdopen(fdo) + errors = fhe.read() + output = fho.read() + + # clean up files + fhe.close() + fho.close() + os.remove(fne) + os.remove(fno) + os.remove(fni) return (output,errors)