You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defrun_cmd(*args, cwd: Optional[str] =None) ->bool:
"""Run system command. Returns: (bool): Whether run successful. Docs test >>> run_cmd('pwd') True >>> run_cmd('which', 'python') True """try:
# ? In python2, `subprocess` not support `with` sentence.proc=subprocess.Popen(" ".join(args), shell=True, cwd=cwd)
proc.wait()
exceptException:
Log.error(traceback_info())
returnFalseelse:
returnTruedefexec_cmd(*args, cwd: Optional[str] =None) ->Tuple[str, str]:
"""Run system command and get result. Returns: (str, str): Error string and result string. """try:
# Take over the input stream and get the return information.withsubprocess.Popen(
" ".join(args),
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
shell=True,
cwd=cwd,
) asproc:
output=proc.communicate()
# Get normal output and error output.res=output[0].decode()
err=output[1].decode()
exceptExceptionase:
Log.error(traceback_info())
returnstr(e), ""else:
returnerr, res
Can use one parameter to contrl whether return result or ouput to shell.
The text was updated successfully, but these errors were encountered:
Can use one parameter to contrl whether return result or ouput to shell.
The text was updated successfully, but these errors were encountered: