开发者

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. 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:

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 runn开发者_运维知识库ing the same command always crashes.

What is being done differently and how can I fix it?


Your code works for me - with perl 5.10.1 on Ubuntu - after I reinserted the missing semicolon at the end of the $rmcmd = .. line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜