Batch file does not run as required from Python.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vivek Ganti
    New Member
    • Jul 2010
    • 3

    Batch file does not run as required from Python.

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

    cd C:\Program Files (x86)\Wireshark
    tshark -i 3 -w "C:\Users\V ivek Ganti\pcap_file .pcap"
    tshark -nr "C:\Users\V ivek Ganti\pcap_file .pcap" -T text > "C:\Users\V ivek 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
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    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!

    Comment

    Working...