title: python or bash script to pass all files in a folder to java command line
body: <p>I have the following Java command line working fine Mac os. </p>
  
  <pre><code>java -cp stanford-ner.jar edu.stanford.nlp.process.PTBTokenizer file.txt &gt; output.txt
  </code></pre>
  
  <p>Multiple files can be passed as input with spaces as follows.</p>
  
  <pre><code>java -cp stanford-ner.jar edu.stanford.nlp.process.PTBTokenizer file1.txt file2.txt &gt; output.txt
  </code></pre>
  
  <p>Now I have 100 files in a folder. All these files I have to pass as input to this command. I used </p>
  
  <p>python os.system in a for loop of directories as follows .</p>
  
  <pre><code>for i,f in enumerate(os.listdir(filedir)):
  
       os.system('java -cp "stanford-ner.jar" edu.stanford.nlp.process.PTBTokenizer "%s" &gt;        "annotate_%s.txt"' %(f,i))
  </code></pre>
  
  <p>This works fine only for the first file. But for all othe outputs like annotate_1,annotate_2 it creates only the file with nothing inside that. I thought of using for loop the files and pass it to subprocess.popen() , but that seems of no hope.</p>
  
  <p>Now I am thinking of passing the files in a loop one by one to execute the command sequentially by passing each file in a bash script. I am also wondering whether I can parallely executes 10 files (atleast) in different terminals at a time. Any solution is fine, but I think this question will help me to gain some insights into different this.</p>