user3517203
user3517203

Reputation: 19

Receive arguments via shell pipe in python?

I have a python file that uses glob to find js files in a particular folder and then prints them:

print glob.glob(printfolder)

I want to receive the filenames found by this file, and pipe them in to another file that counts the lines of code of each of those files

so I'm using:

python findjava.py /home/alien/Desktop/ | python countfile.py -a

(findjava is the script that finds java files, that address is an argument to what directory it should search for those files, and countfile is the file that receives 1 filename and counts its line of codes, the argument -a is to show all (lines of code, comments, and other things it counts)

But I get the following output:

['/home/alien/Desktop/testfile.js']
usage: countfile.py [-h] [-t] [-b] [-s] [-c] [-a] units
countfile.py: error: too few arguments

so countfile is still waiting for the argument with the filename, which I'm trying to get with

import sys
for line in sys.stdin:
    print line

Any thoughts? ;_;

Upvotes: 1

Views: 328

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 114098

print " ".join(glob.glob(printfolder))

I think would work better :P

or maybe

print "\n".join(glob.glob(printfolder))

you are passing in a string like ['asdasd','dsasdad'] ... which almost certainly is not what countfile is expecting

Upvotes: 1

Related Questions