1

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? ;_;

4
  • Consider fileinput Commented Apr 9, 2014 at 21:59
  • You are passing the result of findjava as stdin, not as command-line arguments. If you want to use the output of one command as arguments to another, look at xargs. See this question. Commented Apr 9, 2014 at 22:00
  • Where is countfile accessing the command-line arguments? It's just reading sys.stdin. Commented Apr 9, 2014 at 22:01
  • parser = argparse.ArgumentParser(description='Process a file') parser.add_argument('-t', help='Display total line count', action="store_true") parser.add_argument('-b', help='Display total blank line count', action="store_true") parser.add_argument('-s', help='Display total source line count', action="store_true") parser.add_argument('-c', help='Display total comment line count', action="store_true") parser.add_argument('-a', help='Display all line counts', action="store_true") parser.add_argument('units', action="store") args = parser.parse_args() #print parser.parse_args() file = args.units Commented Apr 10, 2014 at 12:09

1 Answer 1

1
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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.