Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 -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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-07-06 19:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found