0
os.system("'C:\Program Files\Wireshark\tshark.exe' -r B2.pcap -T fields -e frame.number -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e ip.proto -e ip.flags.syn -e ip.flags.nf -e ip.flags.df -e frame.len -E header=y -E separator=, > traffic.csv")

I'm trying to run the above command in python but its reading the \t in the \tshark.exe part as a tab character. How do I solve this?

3 Answers3

2

Raw strings start with the r symbol: r"string with \t \n"

ev-br
  • 24,968
  • 9
  • 65
  • 78
1

try

os.system("'C:\Program Files\Wireshark\\tshark.exe' -r B2.pcap -T fields -e frame.number -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e ip.proto -e ip.flags.syn -e ip.flags.nf -e ip.flags.df -e frame.len -E header=y -E separator=, > traffic.csv")

Backslashes are used to "escape" characters and if you want to print out a backslash, you have to escape it with another backslash

deadshot
  • 8,881
  • 4
  • 20
  • 39
aidan0626
  • 307
  • 3
  • 8
0

Probably because this one is wrapped in string?

"'C:\Program Files\Wireshark\tshark.exe'..."

try using raw string.

deadshot
  • 8,881
  • 4
  • 20
  • 39
Minh-Long Luu
  • 2,393
  • 1
  • 17
  • 39
  • It would be more helpful to show how to use raw string - like this: r”somestring” – Stefan Aug 05 '20 at 04:59
  • Tried this. Same error. The filename, directory name, or volume label syntax is incorrect. This is the error – Sushrut Naik Aug 05 '20 at 05:07
  • I found a similar answer, try this maybe? https://stackoverflow.com/questions/16177104/how-do-i-used-2-quotes-in-os-system-python/16177142#16177142 – Minh-Long Luu Aug 05 '20 at 05:09