2024-10-02 14:20:08 发布
网友
我正在尝试使用包含子进程的文件来查找文件类型
cwdir = os.getcwd() Fileinput=cwdir+"/"+'testfile.zip' print "Current Directory %s"% cwdir Fileformat=subprocess.Popen('file' + Fileinput)
我得到OSError:[Errno 2]没有这样的文件或目录。我验证了,文件确实存在于路径中。 谢谢你的帮助。在
在'file'和{}之间添加空格
'file'
Fileformat = subprocess.Popen('file ' + Fileinput) # ^
否则,file/current/path/testfile.zip将被视为可执行路径,而不是{}。在
file/current/path/testfile.zip
或使用以下表格:
如果要获得命令的输出,必须将stdout=subprocess.PIPE传递给Popen,并使用Fileformat.stdout.read()读取。在
stdout=subprocess.PIPE
Popen
Fileformat.stdout.read()
使用subprocess.check_output怎么样?在
subprocess.check_output
>>> subprocess.check_output(['file', '/etc/passwd']) '/etc/passwd: ASCII text\n'
在}之间添加空格
'file'
和{否则,}。在
file/current/path/testfile.zip
将被视为可执行路径,而不是{或使用以下表格:
^{pr2}$如果要获得命令的输出,必须将
stdout=subprocess.PIPE
传递给Popen
,并使用Fileformat.stdout.read()
读取。在使用
subprocess.check_output
怎么样?在相关问题 更多 >
编程相关推荐