Re: system() rc hosed?

From: Greg G (ggershSNACK_at_CAKEctc.net)
Date: 10/28/03


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



Relevant Pages

  • Re: system() rc hosed?
    ... >myprogram. ... In fact, the return code is 255, which seems to translate to ... So your systemcommand is looking for a program called ... especially if trailing spaces or newlines might be involved. ...
    (comp.lang.perl.misc)
  • Re: Printer Sharing
    ... Here is last command you wanted. ... _f Pre-processing FILTER NAME ... __TRN STAGE 2 TRANSLATE TABLES ... t1 Path Name of First Alternate Stage 2 Translate ...
    (comp.unix.aix)
  • Re: Cant delete files that end with period
    ... Type or paste this command and then hit your Enter key... ... The file name includes an invalid name in the Win32 name space ... the file name has a trailing space or a trailing period ... the trailing spaces or periods are stripped before the actual file ...
    (microsoft.public.windowsxp.general)
  • Re: intepreting code
    ... translate this code that came from our Cisco load balancer. ... If the connection succeeds, ... The 'puts' command prints to the console. ... Everything else is more of the same, except for 'exit' which ends the ...
    (comp.lang.tcl)
  • Re: Run WIN32 App as service
    ... Unpack Srvany.Exe to a folder, like System32 in the Windows folder, ... then open a command window and issue command: ... Open RegEdit, ... If you need more info just ask and I will try to translate. ...
    (microsoft.public.windowsxp.perform_maintain)