- Complete rewrite of Scyther call (also preparing for Mac OS X versions)
This commit is contained in:
parent
aac06d3c43
commit
8f1e1ae8a9
@ -166,28 +166,42 @@ class Scyther(object):
|
|||||||
if self.program == None:
|
if self.program == None:
|
||||||
raise Error.NoBinaryError
|
raise Error.NoBinaryError
|
||||||
|
|
||||||
# Generate a temproary file for the error output
|
# Generate temporary files for the output
|
||||||
errorfile = tempfile.NamedTemporaryFile()
|
# 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
|
# Generate command line for the Scyther process
|
||||||
self.cmd = ""
|
self.cmd = ""
|
||||||
self.cmd += "\"%s\"" % self.program
|
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)
|
self.cmd += " %s %s" % (self.options, args)
|
||||||
|
if spdl:
|
||||||
|
self.cmd += " %s" % fni
|
||||||
|
|
||||||
# Start the process, push input, get output
|
# Start the process
|
||||||
(stdin,stdout) = os.popen2(self.cmd)
|
os.system(self.cmd)
|
||||||
if self.spdl:
|
|
||||||
stdin.write(self.spdl)
|
|
||||||
stdin.close()
|
|
||||||
output = stdout.read()
|
|
||||||
stdout.close()
|
|
||||||
|
|
||||||
# get errors
|
# reseek
|
||||||
self.errors = []
|
fhe = os.fdopen(fde)
|
||||||
errorfile.seek(0)
|
fho = os.fdopen(fdo)
|
||||||
errors = errorfile.read()
|
errors = fhe.read()
|
||||||
errorfile.close()
|
output = fho.read()
|
||||||
|
|
||||||
|
# clean up files
|
||||||
|
fhe.close()
|
||||||
|
fho.close()
|
||||||
|
os.remove(fne)
|
||||||
|
os.remove(fno)
|
||||||
|
os.remove(fni)
|
||||||
|
|
||||||
return (output,errors)
|
return (output,errors)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user