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
  • 83,387
  • 30
  • 160
  • 202
Homap
  • 2,142
  • 5
  • 24
  • 34
  • 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
  • 588,541
  • 66
  • 880
  • 895