Python wget缺少带有shlex和子流程的url

Python wget缺少带有shlex和子流程的url,python,subprocess,wget,shlex,Python,Subprocess,Wget,Shlex,我很难理解为什么会出现wget:missing URL错误: import shlex import subprocess copy_command = "wget -O - 'http://example.com/somepath/somefile.txt?someparam=test' | sshpass -p pass ssh user@localhost -p 2222 \"cat - > /upload/somefile.txt\""

我很难理解为什么会出现
wget:missing URL
错误:

import shlex
import subprocess

copy_command = "wget -O - 'http://example.com/somepath/somefile.txt?someparam=test' | sshpass -p pass ssh user@localhost -p 2222 \"cat - > /upload/somefile.txt\""

cmd = shlex.split(copy_command, posix=False)

with subprocess.Popen(
    cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True
) as proc:
    output, error = proc.communicate()

我错过了什么?如果我只是直接给子进程
copy_命令
字符串,那么它就可以正常工作。

要设置管道,需要父进程生成所有相关程序,并且连接(管道)一个到另一个的stdio

的Python文档解释了如何做到这一点


它与字符串参数和
shell=True
一起工作,因为这样它就把命令行交给了一个子shell,而这个shell处理所有这些细节。

等等,你不能用对Popen的一次调用来模拟整个管道的重定向。您需要多个呼叫,每个进程一个。感谢您的评论!请注意,当我不使用shlex时,这与我预期的一样有效。因为
shell=True
将它作为字符串传递给具有
sh-c'…'
的shell。所以子shell然后解释管道。顺便说一句,我不太确定您在那里尝试做什么,但我确定有更好的方法。假设您在Linux上。