Perl: the Markov chain saw | |
PerlMonks |
Re: Using system to run exe on Windows and pass it variablesby kcott (Archbishop) |
on Sep 15, 2016 at 06:22 UTC ( [id://1171815]=note: print w/replies, xml ) | Need Help?? |
G'day trmn8tr, Welcome to the Monastery. "use warnings; use strict; my $arg1 = $ARGV1; my $arg1 = $ARGV2; my $arg1 = $ARGV3; system('plink.exe -ssh me@myserver -pw password . ./scripts/myscript.sh $arg1 $arg2 $arg3');" Beyond the issue with code tags that stevieb pointed out (i.e. all three [n] parts are rendered as links — described in "What shortcuts can I use for linking to other information?"), you have an additional problem which is probably caused by typing your code in by hand. What you've ended up with is three declarations for $arg1. Had you tried to run this code, it would have failed to compile and aborted something like this:
[Note: I have $PERL5OPT set to '-Mstrict -Mwarnings -Mautodie' (see perlrun)] If you copy and paste your code, you'll avoid these sorts of typos; not to mention saving yourself a lot of unnecessary work. Array indices are zero-based: the first element of @ARGV is $ARGV[0]. Did you really intend to set $arg1 to the 2nd argument ($ARGV[1]), $arg2 to the 3rd argument and $arg3 to the 4th argument? If so, these variables are extremely poorly named and your code is highly error-prone! You might also consider using an array slice (e.g. @ARGV[0..2]). If you're unfamiliar with this construct, see "perlintro: Perl variable types". See the system function documentation. Note that this function takes a list: so use one. There is no benefit in attempting to construct a string in which some parts aren't interpolated (e.g. @myserver) and some parts are (e.g. $arg1). You probably could have removed all three declarations and assignments and just written:
That's obviously untested; this isn't:
— Ken
In Section
Seekers of Perl Wisdom
|
|