problem using system()

problem using system()

am 09.04.2008 14:42:24 von Mike

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

Re: problem using system()

am 09.04.2008 15:18:12 von 1usa

mike wrote in
news:6f8e80dd-1a07-4719-a634-
18f2a21dce0f@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@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/

Re: problem using system()

am 09.04.2008 15:21:07 von Joost Diepenmaat

mike 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/

Re: problem using system()

am 09.04.2008 15:48:29 von jjcassidy

On Apr 9, 8:42=A0am, mike 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

Re: problem using system()

am 09.04.2008 15:57:43 von Mike

Hi,

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


my @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(@args) == 0 or die "system @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 @args in string at
remote_deploy.pl line 63.
syntax error at remote_deploy.pl line 63, near "system"
Global symbol "@args" requires explicit package name at
remote_deploy.pl line 63.
Global symbol "@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

Re: problem using system()

am 09.04.2008 16:21:04 von Japhio

On Apr 9, 3:57 pm, mike wrote:
> Hi,
>
> I changed it to ( taking all pointers into account):
>
> my @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(@args) == 0 or die "system @args failed: $?"

[cut]

> Possible unintended interpolation of @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 "@args" requires explicit package name at
> remote_deploy.pl line 63.
> Global symbol "@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 "@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!

Re: problem using system()

am 09.04.2008 16:25:06 von 1usa

mike wrote in news:ec4401c0-d287-4a12-
9a29-8d67509b7d61@q1g2000prf.googlegroups.com:

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

> system(@args) == 0 or die "system @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@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/

Re: problem using system()

am 09.04.2008 17:21:14 von glex_no-spam

mike wrote:
> Hi,
>
> I changed it to ( taking all pointers into account):
>
>
> my @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 @args = (
$User_Preferences{asadminexecutable},
'deploy',
"--user=$User_Preferences{user}",
"--passwordfile=$User_Preferences{passwordfile}",
"--host=$User_Preferences{host}",
"--port=$User_Preferences{port}",
"$User_Preferences{pathdeployunit}",
);

Re: problem using system()

am 10.04.2008 00:22:04 von benkasminbullock

On Wed, 09 Apr 2008 10:21:14 -0500, J. Gleixner wrote:
> mike wrote:
>> my @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 @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 @jazz = qw/user passwordfile host port/;
my @args = ($User_Preferences{asadminexecutable},
'deploy',
(map "--$_=$User_Preferences{$_}", @jazz),
$User_Preferences{pathdeployunit},
);