我正在使用python 2.6版运行Debian 6。我有两个子进程代码:
rsync_out = subprocess.Popen(['sshpass', '-p', password, 'rsync', '--recursive', source],
stdout=subprocess.PIPE)
command = subprocess.check_call(('grep', '\.'), stdin=rsync_out.stdout)
它的工作方式与我想要的完全一样,但python 2.6没有check_call。如何用subprocess.Popen
调用第二个命令?
尝试过这样但不起作用:
command = subprocess.Popen(['grep', '\.'], stdin=rsync_out.stdout).communicate()[0]
我收到此错误:
'NoneType' object has no attribute 'split'
答案 0 :(得分:0)
我想您正在尝试获取第二个命令的返回码?试试这个:
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