Technext has asked for the wisdom of the Perl Monks concerning the following question:
Now the issue is that though the program runs fine, it prints output after a while. Whole output is captured in $stdout and then dumped later. Since this job runs as a Jenkins job, the end user has no idea what's going on until the output is dumped. I wanted to print each line as event occurs (runtime) instead of waiting for the whole output to be stored in the variable and dumped later. I did read this article but i'm not sure whether it applies to my case and if it does, how can i implement it. Just to mention, efficiency is *not* a concern in my scenario. Any help will really be appreciated.use strict; use warnings; use Cwd; use File::Copy; use Getopt::Long; use File::Basename; use Net::OpenSSH; my ($conf_file, $environment, $doexec, $exec, $job, $dest_file, $user, + $host, $IP, $TARGET_SERVER, $JENKINS_JOB, $wrapper, $src_file, $src_ +path, $src_dist_path, $src_full_path, $id_file, $ssh, @array, $line); init(); sub init { $JENKINS_JOB = $ENV{'JOB_NAME'}; $conf_file = "/home/ec2-user/SCM/conf/deploy_build.conf"; open (FH, "<", $conf_file) or die "Cannot open < $conf_file: $!"; while (<FH>) { if ( $_ =~ /\b$JENKINS_JOB\b/ ) { push @array, $_; } else { next; } } foreach $line (@array) { ($job, $src_path, $dest_file, $user, $wrapper) = split(':', $l +ine); $id_file = "/home/ec2-user/.ssh/priv_key"; $ssh = Net::OpenSSH->new($IP, key_path => $id_file, user => $u +ser); $ssh->error and die "Couldn't establish SSH connection: ". $ss +h->error; printf "\n"; if (length $wrapper) { printf "Initiating subroutine for executing wrapper on rem +ote machine...\n"; &exec_wrapper; } else { printf "*** No wrapper specified ****\n"; } } } sub exec_wrapper { my ($stdout, $errput) = $ssh->capture2("~/release/$wrapper"); printf "Output: $stdout\n" if $stdout; die "Error: $errput\n" if $errput; printf "\n\n\n"; }
|
|---|