How long does it take to run the command manually? It might just take very long to finish.

backticks will wait for the program to end before returning the output, so if the program just takes a long time to stop, you won't see any output since you're capturing it with the backticks. exec will just replace the current program with the new one, so any output of the command will be printed immediately, even if the program is still running.

by the way, if you're not doing anything with the output except printing you could also use system(), which doesn't capture the program's output, so any output will also be printed immediately (while the program is running, before system() returns).

About backticks using exec() - exec() is the only way to start a new program in unix. system(), backtics, piped open etc all use exec() behind the scenes. Calls that execute a command and return do a fork first, then call exec() in the child process. That's why exec() should always be the fastest. Not that you'd normally notice the speed difference - fork() is pretty fast (it has to be - it's the only way to start a new process).


In reply to Re^3: exec vs. backtick-and-assign performance by Joost
in thread exec vs. backtick-and-assign performance by apotheon

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.