Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > system() rc hosed?

Reply
Thread Tools

system() rc hosed?

 
 
Greg G
Guest
Posts: n/a
 
      10-28-2003

I've got some code that looks like this:

@args = ("/usr/local/bin/myprogram ", " -a ", $param1, " -b ",
$param2);
print STDERR @args, "\n";
$rc = 0xffff & system (@args);

It *should* work, but it is patently ignoring the return code from
myprogram. In fact, the return code is 255, which seems to translate to
"command failed". If I capture the output from stderr and run it from
the command line, it works fine.

In fact, this works fine:

$capture = `@args`;
print STDOUT $capture,"\n";

I get the output from the myprogram.

Any ideas what's happening to me here?

-Greg G

 
Reply With Quote
 
 
 
 
Gary E. Ansok
Guest
Posts: n/a
 
      10-28-2003
In article <(E-Mail Removed)>,
Greg G <(E-Mail Removed)> wrote:
>
>I've got some code that looks like this:
>
> @args = ("/usr/local/bin/myprogram ", " -a ", $param1, " -b ",
>$param2);
> print STDERR @args, "\n";
> $rc = 0xffff & system (@args);
>
>It *should* work, but it is patently ignoring the return code from
>myprogram. In fact, the return code is 255, which seems to translate to
> "command failed". If I capture the output from stderr and run it from
>the command line, it works fine.


When you pass system() a list of arguments, as you are doing here,
they are taken exactly as the program to run and the arguments to
pass to it.

So your system() command is looking for a program called
"/usr/local/bin/myprogram " -- without the quotes, but _with_
the trailing space. Also, the first and third arguments to that
program are going to have leading and trailing spaces.

If you want to print out the arguments nicely, I would use
print STDERR join(' ', @args), "\n";
(You could play with the $" variable, which works out to the same thing.)

However, I often prefer something like
print STDERR map(">$_<", @args), "\n";
especially if trailing spaces or newlines might be involved.

Gary
--
Rule #87: If the thought of something makes me giggle for longer than 15
seconds, I am to assume that I am not allowed to do it.
-- www.skippyslist.com
 
Reply With Quote
 
 
 
 
Greg G
Guest
Posts: n/a
 
      10-28-2003
Gary E. Ansok wrote:

> In article <(E-Mail Removed)>,
> Greg G <(E-Mail Removed)> wrote:
>
>>I've got some code that looks like this:
>>
>> @args = ("/usr/local/bin/myprogram ", " -a ", $param1, " -b ",
>>$param2);
>> print STDERR @args, "\n";
>> $rc = 0xffff & system (@args);
>>
>>It *should* work, but it is patently ignoring the return code from
>>myprogram. In fact, the return code is 255, which seems to translate to
>> "command failed". If I capture the output from stderr and run it from
>>the command line, it works fine.

>
>
> When you pass system() a list of arguments, as you are doing here,
> they are taken exactly as the program to run and the arguments to
> pass to it.
>
> So your system() command is looking for a program called
> "/usr/local/bin/myprogram " -- without the quotes, but _with_
> the trailing space. Also, the first and third arguments to that
> program are going to have leading and trailing spaces.
>
> If you want to print out the arguments nicely, I would use
> print STDERR join(' ', @args), "\n";
> (You could play with the $" variable, which works out to the same thing.)
>
> However, I often prefer something like
> print STDERR map(">$_<", @args), "\n";
> especially if trailing spaces or newlines might be involved.


Thanks! That seems to have cleared things up nicely.

-Greg G

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments