mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-08-08 07:40:39 -09:00
Merge remote-tracking branch
'origin/GP-7007_ghidorahrex_pcodetest_BuildUtil_run_fix--SQUASHED' into patch (Closes #9309)
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
##
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -32,32 +33,28 @@ class BuildUtil:
|
||||
|
||||
def run(self, cmd, stdout=False, stderr=False, verbose=True):
|
||||
if isinstance(cmd, str):
|
||||
if stdout and stderr:
|
||||
cmd += ' 1>%s 2>%s' % (stdout, stderr)
|
||||
elif stdout and not stderr:
|
||||
cmd += ' 1>%s 2>&1' % (stdout)
|
||||
elif not stdout and stderr:
|
||||
cmd += ' 2>%s' % (stderr)
|
||||
if verbose: self.log_info(cmd)
|
||||
os.system(cmd)
|
||||
proc = shlex.split(cmd)
|
||||
string = cmd
|
||||
else:
|
||||
string = ' '.join(cmd)
|
||||
proc = cmd
|
||||
string = " ".join(cmd)
|
||||
if verbose: self.log_info(string)
|
||||
try:
|
||||
if stdout:
|
||||
f = open(stdout, 'w+')
|
||||
string += ' 1>%s 2>&1' % (stdout)
|
||||
stdout_f = open(stdout,'w')
|
||||
stderr_f = open(stderr,'w') if stderr else subprocess.STDOUT
|
||||
result = subprocess.run(proc, stdout=stdout_f, stderr=stderr_f)
|
||||
elif stderr:
|
||||
stdout_f = None
|
||||
stderr_f = open(stderr,'w')
|
||||
result = subprocess.run(proc, stdout=stdout_f, stderr=stderr_f)
|
||||
else:
|
||||
f = subprocess.PIPE
|
||||
if verbose: self.log_info(string)
|
||||
try:
|
||||
sp = subprocess.Popen(cmd, stdout=f, stderr=subprocess.PIPE)
|
||||
except OSError as e:
|
||||
self.log_err("Command: " + string)
|
||||
self.log_err(e.strerror)
|
||||
return 0, e.strerror
|
||||
if stdout: f.close()
|
||||
out, err = sp.communicate()
|
||||
# print 'run returned %d bytes stdout and %d bytes stderr' % (len(out) if out else 0, len(err) if err else 0)
|
||||
return out, err
|
||||
result = subprocess.run(proc,capture_output=True)
|
||||
except OSError as e:
|
||||
self.log_err("Command: " + string)
|
||||
self.log_err(e.strerror)
|
||||
return 0, e.strerror
|
||||
return result.stdout, result.stderr
|
||||
|
||||
def isdir(self, dname):
|
||||
return os.path.isdir(dname)
|
||||
|
||||
Reference in New Issue
Block a user