简体   繁体   English

执行命令时将输出发送到perl中的STDOUT

[英]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) . 我正在编写一个perl代码,以将代码从jsvn update .目录(在我的情况下为jsvn update . )。 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. 我希望在进行检查时,结果应显示在stdout中('jsvn update。'确实表明了这一点,但是如果有任何错误,我必须继续查看监视器,如果有错误,我必须给出一个清理并再次开始该过程。)我为此编写了一个程序,但它不会在屏幕上显示输出。 The cursor keeps blinking and i know the process is going on background, but i want to have the results also displayed to stdout. 光标一直闪烁,我知道进程正在进行中,但是我想将结果也显示到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: 如果您想使用IPC :: System :: Simple ,则可以通过$EXITVAL来获取退出值,方法如下:

 ...
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) {

  }
}
 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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