Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何解决包含'|';_Python_Subprocess - Fatal编程技术网

Python 如何解决包含'|';

Python 如何解决包含'|';,python,subprocess,Python,Subprocess,此代码不起作用。 我是这样写的 str = "curl -s 'URL_ADDRESS' | tail -1".split() p = subprocess.Popen(str,stdout=subprocess.PIPE).stdout data = p.read() p.close() print(data) 但是结果是b'。 这有什么问题吗?如果使用子流程,请使用,而不是像这样使用“|” str = "curl -s 'URL_ADDRESS' | tail -1".split() p

此代码不起作用。 我是这样写的

str = "curl -s 'URL_ADDRESS' | tail -1".split()
p = subprocess.Popen(str,stdout=subprocess.PIPE).stdout
data = p.read()
p.close()
print(data)
但是结果是
b'

这有什么问题吗?

如果使用子流程,请使用,而不是像这样使用“|”

str = "curl -s 'URL_ADDRESS' | tail -1".split()
p = subprocess.Popen(str,stdout=subprocess.PIPE).stdout
data = p.read()
p.close()
print(data)
这将解决问题

str = "curl -s 'URL_ADDRESS'".split()

tail = "tail -1".split()

temp = subprocess.Popen(str, stdout=subprocess.PIPE).stdout

temp1 = subprocess.Popen(tail, stdin=temp, stdout=subprocess.PIPE).stdout

temp.close()

data = temp1.read()

temp1.close()