Hi skendric,

In my experience, the best thing is to use modules to help you. A quick glance at the source of File::Which shows that it uses File::Spec internally, so the filenames that which is returning should already be in the native format. You can test this via use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper($tshark_binary); (although keep in mind that the output will be in Perl's notation, so e.g. $VAR1 = "C:\\Foo\\Bar.txt" means that the string is actually C:\Foo\Bar.txt).

As for calling external commands, I would not recommend the system(STRING) form, but instead the system(LIST) form (Update: that is, system called with more than one argument, or even better, the system PROGRAM LIST form), or even better, a module such as 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 Win32::ShellQuote).

Unfortunately I can't test this on Windows at the moment, but I think this should work (it works on Linux): Updated: Tested and works on both Linux and Windows. On Windows, which('tshark') does indeed return "C:\\Program Files\\Wireshark\\tshark.EXE" as I suspected above. Also, as I mentioned below, if tshark is already in your PATH, you don't need the which, it works fine without (run3 ['tshark', ...) on both OSes.

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;

Although, if tshark is already in your $ENV{PATH}, why use which at all?

Hope this helps,
-- Hauke D


In reply to Re: portability / system / elegance (updated) by haukex
in thread portability / system / elegance by skendric

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.