Please forgive me for asking a simple question of python. This is my first time using python.
I'm writing this script on a mac book pro for now. It will probably be deployed on a Centos server later. The script grabs gets file as an argument. I'll deal with processing the output later.
#!/usr/bin/python
import sys
import subprocess
if len(sys.argv) < 2:
print ("Not enough arguments")
print ("Usage: " + sys.argv[0] + " log_file output_file")
print ("i.e. " + sys.argv[0] + " stream.log output.csv")
sys.exit(1)
else:
input = open (sys.argv[1])
output = open (sys.argv[2],'w')
proc = subprocess.Popen("cat " + input.name + " | cut -d ',' -f 3 | sort | uniq | wc -l", shell=True)
print "got here"
output.close()
print "got here22222"
input.close()
I just ran it from a terminal and it executes. However, after it prints out the last
got here22222
there's a delay of a couple seconds and then it prints out 567. However, there's no print 567 in my script above. Does anyone know why it's printing this number? How do I stop it from printing this number? Thanks in advance for any help you can give me.
./test.py a b
got here
got here22222
~/test$ 567
The final stage of your pipeline is wc -l
which is probably generating the number 567
. It takes a few seconds to reach that point.