使用ubuntu 16.04我想要的是使用python在终端上检索输出,我确实引用了以下2个链接: How can I get terminal output in python?
Running shell command from Python and capturing the output
但是作为python的入门者,我无法使其工作,我想要输出的原始代码是
for element in my_images:
os.system('you-get -o videos ' + element)
我的代码如何变成:
for element in my_images:
# value = os.system('you-get -o videos ' + element)
output = subprocess.Popen(os.system('you-get -o videos ' + element), stdout=subprocess.PIPE).communicate()[0]
print(output)
但没有成功,我收到此错误
Traceback (most recent call last):
File "main_twitter.py", line 29, in <module>
output = subprocess.Popen(os.system('you-get -o videos ' + element), stdout=subprocess.PIPE).communicate()[0]
File "/usr/local/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.6/subprocess.py", line 1220, in _execute_child
args = list(args)
TypeError: 'int' object is not iterable