Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a quoting quandry question ;)

I have a command that works fine on the command line of a unix shell...

> doorway $user@$host.$display 'MSG Hello user.'

That works exactly as expected... now... in a script
my $command = "doorway"; my $location = "$user\@$host.$display"; my $arg = "'MSG Hello user'"; my $ret = system($command, $location, $arg,);

The "doorway" command is printing '-1' and $ret is set to '0'. I don't understand. Can anyone tell if my quoting is the problem? The $arg must have the single-quotes in the shell so I assume it needs them passed somehow to the system command.

Thanks for any help.

Replies are listed 'Best First'.
Re: works on command line but not in script
by blakem (Monsignor) on Nov 30, 2001 at 05:31 UTC
    I see two possible issues with this but I don't really know what your intent is....

    First, the single quotes around $arg probably shouldn't be there. In the shell command they are used to distinguish one argument from the next, which is unnecessary with the list form of system

    Second, where are $user $host and $display coming from? You might want to check the value of $location to be sure its what you expect..... perl variables and enviornment variables are different beasties.

    In short, give this a shot:

    my $command = "doorway"; my $location = "$user\@$host.$display"; print "Location = $location\n"; my $arg = "MSG Hello user"; my $ret = system($command, $location, $arg,);

    -Blake

Re: works on command line but not in script
by qslack (Scribe) on Nov 30, 2001 at 08:32 UTC
    Try using the full path to doorway -- it might be that your Perl program's $PATH is different from your shell's.

    Quinn Slack
    perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'