1

I am trying to execute an editcap command inside a python script. Usually, I do it in cmd, but I want to include it in my python script.

editcap –c 10000 C:\Users\Administrator\Desktop\C_datasets\sa1.pcap C:\Users\Administrator\Desktop\C_datasets\outputs\sa1_output.pcap

Just for info, my editcap is installed with wireshark in C:\Program Files\Wireshark. –c option divides my sa1.pcap input file into subfiles having no more than 10000 packets named with the suffix sa1_output.pcap

This is not executable itself, rather including its options and parameters also.

My python script:

import os 

os.system(r' "C:\"Program Files"\Wireshark\editcap –c 10000 "D:\Datasets\Kaggle Dataset\Video\Zoom\Zoom_2.pcap" D:\zoom.pcap "')

Running the above python script in cmd throws:

editcap: The file "ΓÇôc" doesn't exist

I have absolutely no idea what this is. I can't find anything about it. Whereas running the above editcap command from cmd (without python scripting) runs perfectly.

afaq
  • 111
  • 2

1 Answers1

0

You can use subprocess as below:

import subprocess

command = 'C:\"Program Files"\Wireshark\editcap –c 10000 "D:\Datasets\Kaggle Dataset\Video\Zoom\Zoom_2.pcap" D:\zoom.pcap'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
process.wait()
out, err = process.communicate()

Also, make sure you are escaping the nested quotes.

Umakant
  • 2,106
  • 1
  • 7
  • 12