arc*_*e16 -2 python subprocess popen
我试图使用从类似问题获得的以下代码在Python中打印到终端:
cmd = 'test'
output = subprocess.Popen(cmd, stdout=subprocess.PIPE ).communicate()[0]
print(output)
Run Code Online (Sandbox Code Playgroud)
但是这样做会给我输出:
b''
Run Code Online (Sandbox Code Playgroud)
如何修复我的代码以正确输出到终端?
从手册页:
test - check file types and compare values
Run Code Online (Sandbox Code Playgroud)
一个测试文件的程序.当你在命令行上运行它时......它只是不打印任何东西(因为这个命令适用于提供给它的文件名;而且你没有传递任何参数,它根本没什么好说的)
那里的输出告诉你(其中b''表示:字节八位字节的空数组; 有关详细信息,请参见此处).
所以真正的答案在这里:在你开始想知道当你在python中调用它时工具做了什么...直接在shell上运行它.