problem using system()

M

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
 
A

A. Sinan Unur

(e-mail address removed)
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 <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

Joost Diepenmaat

mike said:
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.
 
A

A Dude

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

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
 
M

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{host}","--
port=$User_Preferences{port}","$User_Preferences{pathdeployunit}");

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
 
J

Japhio

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{host}","--
port=$User_Preferences{port}","$User_Preferences{pathdeployunit}");

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!
 
A

A. Sinan Unur

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 <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

J. Gleixner

mike said:
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{host}","--
port=$User_Preferences{port}","$User_Preferences{pathdeployunit}");

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}",
);
 
B

Ben Bullock

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},
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top