problem using system()

Hi,

I have the following string:

my $command = "$User_Preferences{"asadminexecutable"} deploy --user=
$User_Preferences{"user"} --passwordfile=
$User_Preferences{"passwordfile"} --host=$User_Preferences{"host"} --
port=$User_Preferences{"port"} $User_Preferences{"pathdeployunit"}";
system($command);

Global symbol "$command" requires explicit package name at
remote_deploy.pl line 55.
syntax error at remote_deploy.pl line 55, at EOF
Missing right curly or square bracket at remote_deploy.pl line 55,
within string
Execution of remote_deploy.pl aborted due to compilation errors.

Any ideas what I need to do to make it possible to execute the
command?

cheers,

//mike
Mike [ Mi, 09 April 2008 14:42 ] [ ID #1939107 ]

Re: problem using system()

mike <mikaelpetterson [at] hotmail.com> wrote in
news:6f8e80dd-1a07-4719-a634-
18f2a21dce0f [at] s37g2000prg.googlegroups.co
m:

> I have the following string:
>
> my $command = "$User_Preferences{"asadminexecutable"} deploy
> --user= $User_Preferences{"user"} --passwordfile=
> $User_Preferences{"passwordfile"} --host=$User_Preferences{"host"}
> -- port=$User_Preferences{"port"}
> $User_Preferences{"pathdeployunit"}"; system($command);

This is a little silly. You do realize that you do not have string,
right? You have

"$User_Preferences{"

followed by the bareword

asadminexecutable

followed by

"} deploy -- ..."

etc.

> Any ideas what I need to do to make it possible to execute the
> command?

I would recommend using a LIST argument with system in this case
(see perldoc -f system) unless you need some features of the shell:

system $User_Preferences{asadminexecutable},
'deploy',
"--user=$User_Preferences{user}",
"--passwordfile=$User_Preferences{passwordfile}",
"--host=$User_Preferences{host}",
"--port=$User_Preferences{port}",
"$User_Preferences{pathdeployunit}";

Sinan

--
A. Sinan Unur <1usa [at] llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
1usa [ Mi, 09 April 2008 15:18 ] [ ID #1939109 ]

Re: problem using system()

mike <mikaelpetterson [at] hotmail.com> writes:

> Hi,
>
> I have the following string:
>
> my $command = "$User_Preferences{"asadminexecutable"} deploy --user=
^^ ^^ ^^

> $User_Preferences{"user"} --passwordfile=
^^ ^^
> $User_Preferences{"passwordfile"} --host=$User_Preferences{"host"} --
^^ ^^ ^^ ^^
> port=$User_Preferences{"port"} $User_Preferences{"pathdeployunit"}";
^^ ^^ ^^ ^^^^

get rid of all the double quotes in the $hash{"lookup"} constructs. you
don't need them and they break the double quoted string they're
interpolated in.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Joost Diepenmaat [ Mi, 09 April 2008 15:21 ] [ ID #1939110 ]

Re: problem using system()

On Apr 9, 8:42=A0am, mike <mikaelpetter... [at] hotmail.com> wrote:
> Hi,
>
> I have the following string:
>
> my $command =3D "$User_Preferences{"asadminexecutable"} deploy =A0--user=
=3D
> $User_Preferences{"user"} --passwordfile=3D
> $User_Preferences{"passwordfile"} --host=3D$User_Preferences{"host"} --
> port=3D$User_Preferences{"port"} $User_Preferences{"pathdeployunit"}";
> system($command);
>
> Global symbol "$command" requires explicit package name at
> remote_deploy.pl line 55.
> syntax error at remote_deploy.pl line 55, at EOF
> Missing right curly or square bracket at remote_deploy.pl line 55,
> within string
> Execution of remote_deploy.pl aborted due to compilation errors.
>
> Any ideas what I need to do to make it possible to execute the
> command?
>
> cheers,
>
> //mike

Actually, what you have there is a _quoting_ problem.

First of all there is no reason to delimit hash keys with the double
quotes. But if you're going to do that, you shouldn't surround the
whole string literal with double quotes. Use single quotes
( $User_Preferences{'user'} -- if any -- $User_Preferences{user} --
works just fine. ) or surround the thing with the qq operator, to
allow for the embedded double quotes.

For more on qq: perldoc perlop
jjcassidy [ Mi, 09 April 2008 15:48 ] [ ID #1939113 ]

Re: problem using system()

Hi,

I changed it to ( taking all pointers into account):


my [at] args = ($User_Preferences{asadminexecutable}, 'deploy', "--user=
$User_Preferences{user}","--passwordfile=
$User_Preferences{passwordfile}","--host=$User_Preferences{h ost}","--
port=$User_Preferences{port}","$User_Preferences{pathdeployu nit}");

system( [at] args) == 0 or die "system [at] args failed: $?"
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}

I get the following error:

Possible unintended interpolation of [at] args in string at
remote_deploy.pl line 63.
syntax error at remote_deploy.pl line 63, near "system"
Global symbol " [at] args" requires explicit package name at
remote_deploy.pl line 63.
Global symbol " [at] args" requires explicit package name at
remote_deploy.pl line 63.
Execution of remote_deploy.pl aborted due to compilation errors.

Does not really help me as a newbie :-)
Any ideas?

cheers,

//mike
Mike [ Mi, 09 April 2008 15:57 ] [ ID #1939114 ]

Re: problem using system()

On Apr 9, 3:57 pm, mike <mikaelpetter... [at] hotmail.com> wrote:
> Hi,
>
> I changed it to ( taking all pointers into account):
>
> my [at] args = ($User_Preferences{asadminexecutable}, 'deploy', "--user=
> $User_Preferences{user}","--passwordfile=
> $User_Preferences{passwordfile}","--host=$User_Preferences{h ost}","--
> port=$User_Preferences{port}","$User_Preferences{pathdeployu nit}");
>
> system( [at] args) == 0 or die "system [at] args failed: $?"

[cut]

> Possible unintended interpolation of [at] args in string at
> remote_deploy.pl line 63.
> syntax error at remote_deploy.pl line 63, near "system"

^^^ Here is the nasty bit!

> Global symbol " [at] args" requires explicit package name at
> remote_deploy.pl line 63.
> Global symbol " [at] args" requires explicit package name at
> remote_deploy.pl line 63.
> Execution of remote_deploy.pl aborted due to compilation errors.
>

There is a semicolon ';' missing after the line with system().

By the way, from the error message 'Global symbol " [at] args" requires
explicit package name' I infer that you use the strict pragma, which
is a good thing. Now learn to interpret the error messages ;-)

> Does not really help me as a newbie :-)
> Any ideas?

Keep on trying!
Japhio [ Mi, 09 April 2008 16:21 ] [ ID #1939115 ]

Re: problem using system()

mike <mikaelpetterson [at] hotmail.com> wrote in news:ec4401c0-d287-4a12-
9a29-8d67509b7d61 [at] q1g2000prf.googlegroups.com:

> I changed it to ( taking all pointers into account):
>
....

> system( [at] args) == 0 or die "system [at] args failed: $?"

There is a semi-colon missing at the end of that line.

> syntax error at remote_deploy.pl line 63, near "system"

....

> Does not really help me as a newbie :-)

As a newbie, you would be better helped by reading your code more
carefully rather than asking us to figure out every syntax error.

As a newbie, you might want to learn more before writing deployment
scripts if you don't want to ruin your customers.

Sinan

--
A. Sinan Unur <1usa [at] llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
1usa [ Mi, 09 April 2008 16:25 ] [ ID #1939116 ]

Re: problem using system()

mike wrote:
> Hi,
>
> I changed it to ( taking all pointers into account):
>
>
> my [at] args = ($User_Preferences{asadminexecutable}, 'deploy', "--user=
> $User_Preferences{user}","--passwordfile=
> $User_Preferences{passwordfile}","--host=$User_Preferences{h ost}","--
> port=$User_Preferences{port}","$User_Preferences{pathdeployu nit}");

Could also make that easier to read:


my [at] args = (
$User_Preferences{asadminexecutable},
'deploy',
"--user=$User_Preferences{user}",
"--passwordfile=$User_Preferences{passwordfile}",
"--host=$User_Preferences{host}",
"--port=$User_Preferences{port}",
"$User_Preferences{pathdeployunit}",
);
glex_no-spam [ Mi, 09 April 2008 17:21 ] [ ID #1939120 ]

Re: problem using system()

On Wed, 09 Apr 2008 10:21:14 -0500, J. Gleixner wrote:
> mike wrote:
>> my [at] args = ($User_Preferences{asadminexecutable}, 'deploy', "--user=
>> $User_Preferences{user}","--passwordfile=
>> $User_Preferences{passwordfile}","--host=$User_Preferences{h ost}","--
>> port=$User_Preferences{port}","$User_Preferences{pathdeployu nit}");
> Could also make that easier to read:
> my [at] args = (
> $User_Preferences{asadminexecutable}, 'deploy',
> "--user=$User_Preferences{user}",
> "--passwordfile=$User_Preferences{passwordfile}",
> "--host=$User_Preferences{host}",
> "--port=$User_Preferences{port}",
> "$User_Preferences{pathdeployunit}",
> );

my [at] jazz = qw/user passwordfile host port/;
my [at] args = ($User_Preferences{asadminexecutable},
'deploy',
(map "--$_=$User_Preferences{$_}", [at] jazz),
$User_Preferences{pathdeployunit},
);
benkasminbullock [ Do, 10 April 2008 00:22 ] [ ID #1939141 ]
Perl » comp.lang.perl.misc » problem using system()

Vorheriges Thema: Can I use a look-ahead and a look-behind at the same time?
Nächstes Thema: RE Perl Pattern matching