in reply to Python -V command not returning any value

I have very simple program ... Could anyone please tell me how to get the info? thanks --girija

Use the convenience that is Capture::Tiny and the Basic debugging checklist

#!/usr/bin/perl -- use strict; use warnings; use Capture::Tiny qw/ capture /; use Data::Dump qw/ dd /; my @cmd = ( 'python', '-V' ); my( $stdout, $stderr, $exit ) = capture { system { $cmd[0] } @cmd; };; dd({ stdout => $stdout, stderr => $stderr, exit => $exit } ); __END__ { exit => 0, stderr => "Python 2.5\n", stdout => "" }

Replies are listed 'Best First'.
Re^2: Python -V command not returning any value ( Capture::Tiny )
by gjoshi (Sexton) on Sep 28, 2015 at 07:50 UTC
    Hi all, Also found another way to do this
    open STDOUT, '>', "op.txt" or die "Can't redirect STDOUT: $!"; open STDERR, ">&STDOUT" or die "Can't dup STDOUT: $!";
    thanks --girija
Re^2: Python -V command not returning any value ( Capture::Tiny )
by mr_ron (Deacon) on Sep 29, 2015 at 02:46 UTC

    I came up with a solution using IPC::Open3 before reading your posting with more care. I am new to Capture::Tiny and thank you for the introduction. IPC::Open3 also works but Capture::Tiny can provide something simpler. Your code is interesting pedagogically but the example is as complicated as an open3 solution and maybe a little overkill for the problem.

    use strict; use warnings; use Capture::Tiny 'capture_merged'; my $python_ver = capture_merged { system('python', '-V') }; print "Python version is: $python_ver\n";
    Ron