note
haukex
<p>Hi [skendric],</p>
<p>In my experience, the best thing is to use modules to help you. A quick glance at the source of [mod://File::Which] shows that it uses [doc://File::Spec] internally, so the filenames that <c>which</c> is returning should already be in the native format. You can test this via <c>use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper($tshark_binary);</c> (although keep in mind that the output will be in Perl's notation, so e.g. <c>$VAR1 = "C:\\Foo\\Bar.txt"</c> means that the string is actually <c>C:\Foo\Bar.txt</c>).</p>
<p>As for calling external commands, I would not recommend the <c>system(STRING)</c> form, but instead the <c>system(LIST)</c> form (<small><i>Update:</i></small> that is, [doc://system] called with more than one argument, or even better, the <c>system PROGRAM LIST</c> form), or even better, a module such as [mod://IPC::Run3], which allows you to dodge most shell quoting and escaping issues (on Linux, it can avoid the shell completely, and on Windows, it automatically uses [mod://Win32::ShellQuote]).</p>
<p><strike>Unfortunately I can't test this on Windows at the moment, but I think this should work (it works on Linux):</strike> <b>Updated:</b> Tested and works on both Linux and Windows. On Windows, <c>which('tshark')</c> does indeed return <c>"C:\\Program Files\\Wireshark\\tshark.EXE"</c> as I suspected above. Also, as I mentioned below, if [man://tshark] is already in your <c>PATH</c>, you don't need the <c>which</c>, it works fine without (<c>run3 ['tshark', ...</c>) on both OSes.</p>
<c>
use File::Which qw/which/;
use IPC::Run3 qw/run3/;
run3 [which('tshark'), '-r', $pcap, qw/ -e frame.number
-e frame.time_epoch -e ip.src -e ip.id -T text
-T fields -E /,'separator=,'], undef, $temp_file;
</c>
<p>Although, if [man://tshark] is already in your <c>$ENV{PATH}</c>, why use <c>which</c> at all?</p>
<p>Hope this helps,<br>-- Hauke D</p>
1177153
1177153