in reply to Re: PDF output to temp file
in thread PDF output to temp file

`evince bill.pdf >> /home/administrator/temp_1`;
Using backticks here doesn't make sense, because due to the redirection, no output would be returned anyway. A better solution would be either
system('evince bill.pdf >> /home/administrator/temp_1');
or
my $errmsg=`evince bill.pdf 2>&1 >> /home/administrator/temp_1`;
Another alternative to consider is IPC::Run. This would spawn the command without the need of an auxiliary shell process.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: PDF output to temp file
by kcott (Archbishop) on Mar 22, 2012 at 11:16 UTC
    Using backticks here doesn't make sense, because due to the redirection, no output would be returned anyway.

    I disagree. AM said that he wanted the output redirected: "I want to redirect the output of a terminal cmd on linux to a output file .". I wasn't about to make guesses based on his code. I did, however, point out issues with the code and queried his use of $rc.

    -- Ken

      The reason why I think system makes more sense than backticks in this example, is, that the usage of backticks implies that the output is used somehow. Think about readability: If we see in a code a backticked expression, where the value is not used, we think that maybe the code is not what the write had expected. If you use system instead, you communicate to the reader more clearly what's going on.

      Or, to approach it from a different perspective: Under what conditions would you choose, to use system($cmd) instead of `$cmd`?

      -- 
      Ronald Fischer <ynnor@mm.st>

        G'day Ronald,

        I think it's possible that we've both slightly misconstrued the other's intent and that this has been exacerbated with each response. I'll address both the general issue of system($cmd) vs. `$cmd` and then look at the more specific case raised by AM.

        In general, I avoid platform-specific code. On the rare occasions when this isn't the case, I'm more likely to choose system($cmd) for exactly the reasons you state: "you communicate to the reader more clearly what's going on". I believe we're in agreement with respect to this general case of usage. If I have a reason not to use system(), I'd normally choose qx{$cmd} over `$cmd`.

        AM's original question contained garbage code. I cobbled together various elements of what he had, to produce something which did what he asked for: temp_1, >>/home/administrator and `evince bill.pdf`; was munged into `evince bill.pdf >> /home/administrator/temp_1`;. I retained the append mode (>>) which he'd used although I'm not convinced that he didn't actually want write mode (>); similarly, I retained the backquotes. I stated that I didn't think he'd described what he really wanted and queried what he was using $rc for.

        -- Ken