1 2 3 4 5 6 7 8 9 10 11
| def _command_execute(command_s): """执行命令,例如command_s=['ls', '-al']""" sp = Popen(command_s, stdout=PIPE, stderr=STDOUT, close_fds=True) output_content = '' for line in iter(sp.stdout.readline, b''): output_content += line if len(output_content) > 1024 * 4: break sp.wait() return int(sp.returncode), output_content
|