简体   繁体   中英

Sending output to STDOUT in perl while executing a command

I am writing a perl code to upload code from a repro to a directory( jsvn update . a shell comand in my case) . I wanted that while the check in is going on, the result should display in stdout ('jsvn update .' does show that but i have to keep on looking at the monitor in case of any error and incase of error i have to give a clean up and start the process again.) I wrote a program for that, but it doesnot displays output to screen. The cursor keeps blinking and i know the process is going on background, but i want to have the results also displayed to stdout. Please help me.

#!usr/bin/perl

use Capture::Tiny qw/tee/;


sub code(){

`jsvn cleanup .`;

($stdout, $stderr, @result) = tee { system( "jsvn update ." ) };

print "@result\n";

}

code();

if($stderr){

code(); 

}else{
print "The checkout has been done successfully \n";

exit;
}

If you wanna use IPC::System::Simple you could grab exit values through $EXITVAL doing something like this:

 ...
use IPC::System::Simple qw[capture $EXITVAL];
use feature qw[switch];
 ...
my @result = capture('jsvn update .');

given ($EXITVAL) {
  when (0) {
    print "Ok\n";
  }

  when (1) {

  }
   ..
  when (N) {

  }
}
 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM