简体   繁体   English

在python中使用“cat”时出现“没有这样的文件或目录”错误

[英]"No such file or directory" error when using "cat" in python

When I use当我使用

cat folder1/folder2/*_in.txt>>output.txt 

directly in the terminal, it works fine.直接在终端中,它工作正常。

But when I call from inside the python process, it shows an error "No such file or directory" :但是当我从 python 进程内部调用时,它显示一个错误"No such file or directory"

command = "cat "+path+"*_in.txt >> " + output_variable
print(command) # print exactly the same.
os.system(command) # error : cat: folder1/folder2/*_in.txt: No such file or directory

This happens when there are no files matching the pattern:当没有与模式匹配的文件时会发生这种情况:

$ python -c 'import os; os.system("cat *.txt")'
cat: '*.txt': No such file or directory

$ echo 'Hello World' > myfile.txt

$ python -c 'import os; os.system("cat *.txt")'
Hello World

Be aware that files are matched relative to the process's current working directory ( os.getcwd() ), and not relative to the Python file.请注意,文件与进程的当前工作目录 ( os.getcwd() ) 相关,而不是与 Python 文件相关。 If you can't figure out the working directory and correct relative path to your files, use absolute paths.如果您无法确定工作目录和正确的文件相对路径,请使用绝对路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用带有 hadoop 的 cat 命令时没有这样的文件或目录 - No such file or directory when using cat command with hadoop 出现错误:FileNotFoundError: [Errno 2] No such file or directory when using Python open() - Getting error: FileNotFoundError: [Errno 2] No such file or directory when using Python open() 在Cygwin中使用Python的startapp时,没有此类文件或目录错误 - No such file or directory error when using Python's startapp in Cygwin 使用 python 脚本中的 cat 命令时收到错误消息“raise CalledProcessError(retcode, cmd)” - Getting the error message "raise CalledProcessError(retcode, cmd)" when using the cat command from a python script "使用字体的 Python pygame 错误:没有这样的文件或目录" - Python pygame error using font: no such file or directory Python:使用xlrd时没有目录/文件 - Python: No directory/ file when using xlrd 错误:无法打开需求文件:[Errno 2] 没有这样的文件或目录:'requirements.txt' 使用 AWS Lambda 和 Python 时 - ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' When using AWS Lambda and Python 使用 __file__ 时出现 Python 错误 [WinError 123](文件名、目录名或卷标语法不正确) - Python error [WinError 123] (File name, directory name or volume label syntax incorrect) when using __file__ 使用鼻子测试时出现“没有这样的文件或目录”错误 - 'No such file or directory' error when using nosetests 使用“ PRINT”时,“无此文件或目录”错误信息 - 'No such file or directory' ERROR information when using “PRINT”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM