in reply to PDF output to temp file

This statement does what you're describing:

`evince bill.pdf >> /home/administrator/temp_1`;

Although, I'm not sure that you've really described what you want to do. For instance, what is $rc for?

In any event, you should take a look at the documentation for the open function. Your code indicates that you don't really understand how this works: the first argument is a filehandle not the filename; the filename (possibly as a full pathname) goes where you have the administrator's home directory. You're likely to break something with code like this!

-- Ken

Replies are listed 'Best First'.
Re^2: PDF output to temp file
by rovf (Priest) on Mar 22, 2012 at 09:10 UTC
    `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>
      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>
Re^2: PDF output to temp file
by Anonymous Monk on Mar 22, 2012 at 09:06 UTC

    It gives me this error when it try to run the above command -->Cannot parse arguments: Cannot open display:

      I hadn't come across evince before but find I have it on my system (Mac OS X):

      $ perl -Mstrict -Mwarnings -E '`evince --help >> fred`;' $ cat fred Usage: evince [OPTION...] [FILE…] GNOME Document Viewer ...

      As you can see, I successfully redirected the output of the command to an output file. This is what you asked for (which I queried).

      Given that I now know that this launches a document viewer, I'm wondering exactly what sort of output you're hoping to redirect to a file.

      I probably can't be much help with the error you're getting except to suggest checking that your X Server is running correctly and $ENV{DISPLAY} has an appropriate value.

      -- Ken