Python子流程.Popen()失败

2024-09-27 00:21:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图执行此命令,但失败:

cmdp = ("ps --ppid 1 -f | grep interactive > test.out")
sp = subprocess.Popen(cmdp, shell = True, stdout=subprocess.PIPE, 
        stderr=subprocess.PIPE)
name, err = sp.communicate()
rc = sp.wait()

rc返回为1,并且test.out未创建

如果我在终端中运行ps --ppid 1 -f | grep interactive > test.out,它工作得很好,test.out就会被创建。在


Tags: test命令trueshelloutgrepspinteractive

热门问题