allow potential special characters "@" and "$" in system call

allow potential special characters "@" and "$" in system call

am 06.12.2007 17:32:03 von wong_powah

I want to change a system call to allow potential special characters
'@' and '$'.
This work for regular character in $PASSWORD.
$rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p $PASSWORD
1>login.out 2>login.err");
How to change it to a form that allow potential special characters '@'
and '$' in $PASSWORD?

I tried this, but it does not work:
$rc = system "/usr/lunasa/bin/salogin", "-i 1234:5678 -s 3 -o -p
$PASSWORD 1>salogin.out 2> salogin.err";

print "rc $rc";

rc 65280

Re: allow potential special characters "@" and "$" in system call

am 06.12.2007 17:43:07 von glex_no-spam

wong_powah@yahoo.ca wrote:
> I want to change a system call to allow potential special characters
> '@' and '$'.
> This work for regular character in $PASSWORD.
> $rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p $PASSWORD
> 1>login.out 2>login.err");
> How to change it to a form that allow potential special characters '@'
> and '$' in $PASSWORD?
>
> I tried this, but it does not work:
> $rc = system "/usr/lunasa/bin/salogin", "-i 1234:5678 -s 3 -o -p
> $PASSWORD 1>salogin.out 2> salogin.err";
>
> print "rc $rc";
>
> rc 65280

$rc = system "/usr/lunasa/bin/salogin -i 1234:5678 -s 3 -o -p
\"$PASSWORD\" 1>salogin.out 2> salogin.err";

Re: allow potential special characters "@" and "$" in system call

am 06.12.2007 19:02:30 von Sherm Pendley

wong_powah@yahoo.ca writes:

> I want to change a system call to allow potential special characters
> '@' and '$'.
> This work for regular character in $PASSWORD.
> $rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p $PASSWORD
> 1>login.out 2>login.err");
> How to change it to a form that allow potential special characters '@'
> and '$' in $PASSWORD?

Most shells have the same interpolation rules as Perl - in fact, that's
where Perl borrowed its rules from. So if you want to allow this, you'll
need to use single quotes around that parameter:

$rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p
'$PASSWORD' 1>login.out 2>login.err");

> I tried this, but it does not work:
> $rc = system "/usr/lunasa/bin/salogin", "-i 1234:5678 -s 3 -o -p
> $PASSWORD 1>salogin.out 2> salogin.err";

I wouldn't expect it to work - you're trying to redirect stdout and stderr,
which would require the command to be parsed by a shell interpreter. But,
the multi-argument form of system() bypasses the shell and directly runs
specified program. Also, the multi-argument form doesn't split its args,
so the above will run the salogin command and pass that whole string as
its first parameter - including the spaces.

If you didn't need to redirect stdout and stderr, you could use the multi-
argument form of system(), thereby avoiding the need to worry about shell
interpolation and the need to escape shell metacharacters:

$rc = system('/usr/local/bin/mylogin', '-i', '1234:5678', '-s', '3',
'-o', '-p', $PASSWORD);

> print "rc $rc";
>
> rc 65280

Note that the return value from system() is not just the exit code from
mylogin - it's that, plus some other information. To properly handle it,
you need to use this snippet of code, taken from "perldoc -f system":

You can check all the failure possibilities by inspecting $?
like this:

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

sherm--

--
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net