0

I want to gunzip a series of files and then redirect the output to my python script. The python script gets one argument as the input. 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.

Chris Seymour
  • 79,902
  • 29
  • 153
  • 193
Homap
  • 1,990
  • 3
  • 21
  • 31
  • You're reading input from stdin, checkout http://stackoverflow.com/questions/1450393/how-do-you-read-from-stdin-in-python – zyxue Aug 31 '15 at 17:31

1 Answers1

3

sys.argv is for command-line arguments. You're not passing any of those, you're piping it in via stdin. So you need to read from sys.stdin.

Daniel Roseman
  • 567,968
  • 59
  • 825
  • 842