in reply to Re: Executing perl program from another perl program and capturing the output
in thread Executing perl program from another perl program and capturing the output

The list form of system won't help you on windows.

If your paths don't include quotes, system can help you on windows, if you use Capture::Tiny

use Capture::Tiny qw/ capture /; my($stdout, $stderr, $exit) = capture { system { $args[0] } @args; };;

If you have quotes in your paths then Win32::ShellQuote comes to the rescue

  • Comment on Re^2: Executing perl program from another perl program and capturing the output
  • Download Code

Replies are listed 'Best First'.
Re^3: Executing perl program from another perl program and capturing the output
by BrowserUk (Patriarch) on Nov 25, 2014 at 04:03 UTC
    If ... if ... Capture::Tiny. If ... then Win32::ShellQuote ...

    Just unnecessary! (Ie. A waste of time and effort.)

    If the shell (cmd.exe) requires quotes ...:

    C:\test>"c:\Program Files\Direct Modeling Express 4.0\binx64\7za.exe" +a -y c:\junk.rar "c:\Program Files\Hitman Pro 3.5\*" 7-Zip (A) 4.42 Copyright (c) 1999-2006 Igor Pavlov 2006-05-14 Scanning Creating archive c:\junk.rar Compressing HitmanPro35_x64.exe Everything is Ok

    Then invoking the same command via the shell, via backticks also requires, (and will work with) quotes ... (but use / instead of \ for paths!)

    [0] Perl> $output = `\"c:/Program Files/Direct Modeling Express 4.0/bi +nx64/7za.exe\" a -y c:/junk.rar \"c:/Program Files/Hitman Pro 3.5/*\" +`;; [0] Perl> print $output;; 7-Zip (A) 4.42 Copyright (c) 1999-2006 Igor Pavlov 2006-05-14 Scanning Updating archive c:/junk.rar Compressing HitmanPro35_x64.exe Everything is Ok

    And that's *all* that is required. No ifs; no buts; learn the rules, and it just works.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      And that's *all* that is required. No ifs; no buts; learn the rules, and it just works.

      Yeah, I stick to learning perl quoting rules, and then don't worry about cmd.exe quoting rules too much

        I stick to learning perl quoting rules,

        That's all I'm asking you to do.

        If the backticks command needs double quotes, then you need to precede them with a backslash. That's standard "perl quoting rules".

        Of course, knowing that the command needs double quotes on Windows (rather than single quotes on *nix), requires an open mind and a desire to understand.

        Trying to apply standard English grammar or pronunciation rules to French (or Dutch or German or Russian) ... is pointless.

        Equally, trying to "speak *nix" to Windows, is like the archetypal Englishman, speaking English, S-L-O-W-L-Y A-N-D L-O-U-D-L-Y, to "dear 'ol johnny foreigner", regardless of his nationality.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.