views:

74

answers:

1

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 running the same command always crashes.

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

A: 

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.

David Knell
Works for me aswell on Ubuntu.
szbalint