I need to run a command till the system I’m testing fails, or I abort the script. The command I need to run may vary, so I’m taking it as a command-line argument in quotes. But I can’t seem to be able to run a command-line argument using the system command. Here’s what I tried so far (edited my attempt with the script that @Cfreak provided, even with which I see the same issue):
#!/usr/bin/perl
while(1)
{
print "Iteration #: $count\n";
$retval = system ($ARGV[1]);
if( $retval != 0 ) {
print "System call $ARGV[1] failed with code $retval\n";
}
$count++;
}
If I do
./run ls
I see the following prints:
System call failed with code 65280
Iteration #: 1
System call failed with code 65280
Iteration #: 2
What am i doing wrong here ?
I believe that you want $ARGV[0] and not $ARGV[1]. You might also want to check to be sure that $ARGV[0] is present.