Re: using variable inside system call
by pbeckingham (Parson) on Apr 02, 2004 at 14:46 UTC
|
change the single-quoted string for a double-quoted one, change $[node] to ${node}, escape those double quotes within the string, and beware of the quotes in general with respect to what actually gets passed to the shell.
system ("wrunprb \"*\" \"*\" \"*\" ${node}");
| [reply] [d/l] [select] |
Re: using variable inside system call
by pelagic (Priest) on Apr 02, 2004 at 14:50 UTC
|
Your variable is not interpreted inside single quotes (').
Try this instead:
system ('wrunprb', '"*"', '"*"', '"*"', $node);
pelagic
-------------------------------------
I can resist anything but temptation.
| [reply] [d/l] |
|
|
The original poster has:
system ('wrunprb "*" "*" "*" $[node]');
Assuming the quotes gets fixed such that $node
gets interpolated, that causes wrunprb to be called
with three arguments (assuming $node doesn't contain
whitespace), of which the first two are *. That's
just an asteriks, nothing else. Your suggestion causes
wrunprb to be called with three arguments (even if
$node contains whitespace), of which the first two
are "*", that is, including the quotes.
Since we do not know what's inside $node (it may
contain things which are special to the shell), suggesting
it to replace it with something that bypasses the shell without pointing out this fact shouldn't be done. It's just
not the same, even if it looks the same. Furthermore, even
if $node doesn't contain anything that's special to the
shell, your solution is still different.
Abigail
| [reply] [d/l] |
|
|
| [reply] |
Re: using variable inside system call
by tinita (Parson) on Apr 02, 2004 at 14:50 UTC
|
i don't know what a node is in your example, but what doesn't
work and what error message do you get?
generally, system() with a list as parameters is safer than
a string, so maybe calling
system(qw(wrunprb * * *), $node);
will work. but that's just a guess.
i suppose $[node] is just a typo...
update: ah, i didn't recognize the single quotes. anyway, $[node] is a syntax error. | [reply] [d/l] [select] |
|
|
| [reply] |
|
|
Well, calling system with a list as parameters isn't necessarely 'safer'.
ok, granted, i meant 'in most cases'. in most cases you don't need the shell. i think. (!)
Since you don't know what's inside $node, you don't know whether it matters or not.
that's what i said. i said i don't know what's a 'node' supposed to be. i stated clearly that i'm making a guess.
Don't suggest alternatives without pointing out what may break.
if i always pointed all things that could possibly go wrong i wouldn't have
time for anything else. what is perlmonks all about if i can't suggest alternatives when i state at the same time that i'm guessing? ok, a link to the system() function would have been nice.
| [reply] |