简体   繁体   English

Perl系统命令无法正常显示

[英]Perl system command not acting as a normal prompt

I am trying to modify a perl script to comment out all lines matching some pattern. 我正在尝试修改perl脚本,以注释掉匹配某种模式的所有行。 In normal command prompt, here is the line I'm trying to add: 在正常的命令提示符下,这是我要添加的行:

grep -lIRZ --exclude="*\.svn*" "pattern" . | xargs -0 -l sed -i -e 's/.*pattern.*/\/\/&/g'

Here it is in the context of the perl script: 这是在perl脚本的上下文中:

my $rmcmd = "grep -lIRZ --exclude=\"*\\.svn*\" \"pattern\" . | xargs -0 -l sed -i -e 's/.*pattern.*/\\/\\/&/g'";
runcmd($rmcmd);
...
sub runcmd {
    my @cmd = @_;
    print "Running: @cmd\n";
    system(@cmd);
    # Get  status from system
    my $ret = $? >> 8; 

    if ($ret) {  
        print "-E- command completed with error code $ret.\n"; 
        exit(1); 
    }
    return ($ret);
}

Everything works properly when run from a command prompt, but the script running the same command always crashes. 从命令提示符运行时,一切正常,但是运行同一命令的脚本始终崩溃。

What is being done differently and how can I fix it? 有什么不同的做法,我该如何解决?

在$ rmcmd = ..行末尾重新插入缺少的分号后,您的代码对我有用-在Ubuntu上使用perl 5.10.1。

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

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