如何使用Popen而不是check\u call?

2024-09-30 22:11:55 发布

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

我用pythonversion2.6运行debian6squise。我有两个类似的子流程代码:

rsync_out = subprocess.Popen(['sshpass', '-p', password, 'rsync', '--recursive', source], 
                     stdout=subprocess.PIPE)
command = subprocess.check_call(('grep', '\.'), stdin=rsync_out.stdout)

它的工作方式与我想要的完全一样,但是python2.6没有check_调用。如何使用subprocess.Popen调用第二个命令?在

试过了,但没用:

^{pr2}$

我得到这个错误:

'NoneType' object has no attribute 'split'

Tags: 代码sourcecheckstdoutpassword流程outcommand
1条回答
网友
1楼 · 发布于 2024-09-30 22:11:55

我想让你回第二个命令?试试这个:

rsync_out = subprocess.Popen(['sshpass', '-p', password, 'rsync', ' recursive', source],
                 stdout=subprocess.PIPE)
command = subprocess.Popen(['grep', '\.'], stdin=rsync_out.stdout)
command.communicate()
returnCode = command.returncode

相关问题 更多 >