简体   繁体   English

将Gunzip输出重定向到python脚本

[英]Redirect gunzip output to python script

I want to gunzip a series of files and then redirect the output to my python script. 我想gunzip一系列文件,然后将输出重定向到我的python脚本。 The python script gets one argument as the input. python脚本获取一个参数作为输入。 I wrote the following command: 我写了以下命令:

for i in $(ls test5/*/*gz); do gunzip -c $i | python script.py ; done

But it gives me the following error: 但这给了我以下错误:

Traceback (most recent call last):
  File "./fqtofa.py", line 7, in <module>
    inFile = sys.argv[1]
IndexError: list index out of range

I wonder why it can't read from the gunzip output. 我想知道为什么无法从gunzip输出中读取它。

sys.argv is for command-line arguments. sys.argv用于命令行参数。 You're not passing any of those, you're piping it in via stdin. 您没有传递任何这些,而是​​通过stdin进行传递。 So you need to read from sys.stdin . 因此,您需要阅读sys.stdin

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM