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

user3517203
  • 19
  • 1
  • 2
  • Consider [fileinput](https://docs.python.org/2/library/fileinput.html) – kojiro Apr 09 '14 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](http://stackoverflow.com/questions/1504867/pipe-standard-input-and-command-line-arguments-in-bash). – BrenBarn Apr 09 '14 at 22:00
  • Where is `countfile` accessing the command-line arguments? It's just reading `sys.stdin`. – Barmar Apr 09 '14 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 – user3517203 Apr 10 '14 at 12:09

1 Answers1

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

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179