Re: system() rc hosed?
From: Greg G (ggershSNACK_at_CAKEctc.net)
Date: 10/28/03
- Next message: Alan J. Flavell: "Re: strange effect with [:lower:] in perl"
- Previous message: Gunnar Hjalmarsson: "Re: Finding out if a string has a trailing slash"
- In reply to: Gary E. Ansok: "Re: system() rc hosed?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Oct 2003 15:35:00 -0500
Gary E. Ansok wrote:
> In article <Z_SdncAtxfhQUAOiRVn-gA@ctc.net>,
> Greg G <ggershSNACK@CAKEctc.net> 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
- Next message: Alan J. Flavell: "Re: strange effect with [:lower:] in perl"
- Previous message: Gunnar Hjalmarsson: "Re: Finding out if a string has a trailing slash"
- In reply to: Gary E. Ansok: "Re: system() rc hosed?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|