Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Redirect output of the system() command

by monsoon (Pilgrim)
on Jul 11, 2012 at 04:56 UTC ( #981001=note: print w/replies, xml ) Need Help??

in reply to Redirect output of the system() command

You can invoke shell in the 'system' call. Working example from Windows
system( "cmd /C \"h2p\\wkhtmltopdf.exe", " +d=980995", "out.pdf", "2>nul\"" );

That would be 'bash -c' on Linux I think. This is non portable though, so backticks, which Athanasius already mentioned, are probably your best bet.

Replies are listed 'Best First'.
Re^2: Redirect output of the system() command
by Gangabass (Vicar) on Jul 11, 2012 at 05:33 UTC

    Thank you for the hint with bash -c!

    I have fixed issues with this (really ugly) code:

    my @options = qw( --orientation Landscape --load-error-handling ignore --page-size A3 --quiet ); $config->{wkhtmltopdf_path} =~ s{ }{\\ }g; $config->{result_filename} =~ s{ }{\\ }g; my $command = "(" . join(" ", $config->{wkhtmltopdf_path}, @options, $ +source_file, $config->{result_filename}) . ")"; system( "/bin/bash -c \"$command\" >/dev/null 2>&1" );
      A bit modified version (as soon as I need to quote some options too):
      my @options = qw( --orientation Portrait --page-size A4 --title "Rechnung" --footer-right "created by Manager" ); $config->{wkhtmltopdf_path} =~ s{ }{\\ }g; $source_file =~ s{ }{\\ }g; $config->{result_filename} =~ s{ }{\\ }g; my $command = "(" . join(" ", $config->{wkhtmltopdf_path}, @options, $ +source_file, $config->{result_filename}) . ")"; $command =~ s/\"/\\\"/g; system( "/bin/bash -c \"$command\" >/dev/null 2>&1" );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981001]
and the pool shimmers...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-06-21 10:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.