By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

Batch file does not run as required from Python.

P: 3
I have made a batch file (auto.bat) as follows:

cd C:\Program Files (x86)\Wireshark
tshark -i 3 -w "C:\Users\Vivek Ganti\pcap_file.pcap"
tshark -nr "C:\Users\Vivek Ganti\pcap_file.pcap" -T text > "C:\Users\Vivek Ganti\myoutput.txt"

This is basically to start Wireshark, sniff packets, save it on a pcap file, and then export it to a text file so i can later parse the file.

When i run "auto.bat" from the cmd prompt, it runs great- stores the pcap file and the exported text file.

But when i do os.system("auto.bat") or subprocess.call ("auto.bat"), it does not store the pcap file or the exported txt file. On the Python shell i get a return code of 0 (though the command window opens and captures packets- just doesnt save them in a file).

Please help.

Thank you very much,
Vivek
Jul 27 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 391
Return code of 0 means that it has successfully run the script.

I'm guessing that the issue is the directory that your running in. You can change the current working directory (cwd) in python before running the script.

I think that probably not doing so will just run auto.bat wherever you happen to be, so the auto.bat that you want to run is not being found. However, there is possibly a universal auto.bat that is being found and being run which is why it runs without error.

Try changing your file name to auto2.bat or something, and see if the python code throws an error. If it does then it's probably something like the above!
Aug 3 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.