0

I have a simple program, part of which is to open other programs, for example a web browser.

It does this fine with os.system(sudo "program") but once the program is open I can't do anything with the original python program until the new one closes. Is there any way I could stop this from happening?

4

1 回答 1

1

子进程。子进程模块将控制权返回给 python 并通过管道获取结果。

import subprocess as sp
proc = sp.Popen(["program", "arg1", "arg2"], shell=False, stdout=sp.PIPE, stderr=sp.PIPE)
ret, err = proc.communicate()

“程序”从 proc= .... 开始,但是当您调用 proc.communicate(); 时结果(消息、错误)进入管道;如果不是这种情况,您可以跳过 stderr=sp.PIPE 。

于 2013-09-29T11:20:23.583 回答