我在这里看到了最奇怪的结果,并希望有人可以向我解释这个问题。
因此,我使用find命令查找.log类型的所有文件,并将该命令的结果传递给python脚本。只有find命令的第一个结果是通过管道输出到xargs,或者xargs接收所有结果并将它们作为字符串传递给python脚本。
示例:
# Find returns 3 .log files
find . -name "*.log"
file1.log
file2.log
file3.log
# xargs only runs the python script for first found file (or all 3 are being piped to script as a single string, and only first result is read in)
find . -name "*.log" | xargs python myscript.py -infile
Success: parsed file1.log
我想要发生的是为所有找到的3个文件运行的python脚本。
find . -name "*.log" | xargs python myscript.py -infile
Success: parsed file1.log
Success: parsed file1.log
Success: parsed file1.log