I'm trying to decipher some Perl code which runs on a Windows server, and I ran into this:
$cmd = "./psexec.exe \\\\" . $server_name
I think the idea is to end up with
./psexec.exe \server
but WTF eight backslashes? Does that make any sense? If so, can someone ELI5?
Kevin
I should add that this gets run immediately after via
my $output = `$cmd`
if that makes any difference.
On Mon, Dec 12, 2016 at 1:40 PM, Kevin McGregor kevin.a.mcgregor@gmail.com wrote:
I'm trying to decipher some Perl code which runs on a Windows server, and I ran into this:
$cmd = "./psexec.exe \\\\" . $server_name
I think the idea is to end up with
./psexec.exe \server
but WTF eight backslashes? Does that make any sense? If so, can someone ELI5?
Kevin
Yup, makes sense now...
After this line...
$cmd = "./psexec.exe \\\\" . $server_name
... the cmd variable will contain "./psexec.exe \\server" (4 backslashes. On running this line...
my $output = `$cmd`
... the shell will see "./psexec.exe \\server", and the command will see (after shell quote processing) argv[1] set to "\server".
Each level of "" escape processing requires that you double the number of "" characters entered to get one through. If you want to end up with 2, after 2 levels, you need 8.
Gilbert
On 12/12/2016 1:43 PM, Kevin McGregor wrote:
I should add that this gets run immediately after via
my $output = `$cmd`
if that makes any difference.
On Mon, Dec 12, 2016 at 1:40 PM, Kevin McGregor <kevin.a.mcgregor@gmail.com mailto:kevin.a.mcgregor@gmail.com> wrote:
I'm trying to decipher some Perl code which runs on a Windows server, and I ran into this: $cmd = "./psexec.exe \\\\\\\\" . $server_name I think the idea is to end up with ./psexec.exe \\server but WTF eight backslashes? Does that make any sense? If so, can someone ELI5? Kevin
Ugh. Even under Windows, doesn't
$cmd = "./psexec.exe //" . $server_name
work the same? Is there any need to use backslashes here?
On Mon, Dec 12, 2016 at 1:53 PM, Gilbert E. Detillieux < gedetil@cs.umanitoba.ca> wrote:
Yup, makes sense now...
After this line...
$cmd = "./psexec.exe \\\\" . $server_name
... the cmd variable will contain "./psexec.exe \\server" (4 backslashes. On running this line...
my $output = `$cmd`
... the shell will see "./psexec.exe \\server", and the command will see (after shell quote processing) argv[1] set to "\server".
Each level of "" escape processing requires that you double the number of "" characters entered to get one through. If you want to end up with 2, after 2 levels, you need 8.
Gilbert
On 12/12/2016 1:43 PM, Kevin McGregor wrote:
I should add that this gets run immediately after via
my $output = `$cmd`
if that makes any difference.
On Mon, Dec 12, 2016 at 1:40 PM, Kevin McGregor <kevin.a.mcgregor@gmail.com mailto:kevin.a.mcgregor@gmail.com> wrote:
I'm trying to decipher some Perl code which runs on a Windows server, and I ran into this: $cmd = "./psexec.exe \\\\\\\\" . $server_name I think the idea is to end up with ./psexec.exe \\server but WTF eight backslashes? Does that make any sense? If so, can someone ELI5? Kevin
-- Gilbert E. Detillieux E-mail: gedetil@cs.umanitoba.ca Dept. of Computer Science Web: http://www.cs.umanitoba.ca/~ge detil/ University of Manitoba Phone: (204)474-8161 Winnipeg MB CANADA R3T 2N2 Fax: (204)474-7609 _______________________________________________ Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
That may actually be command-specific. I don't remember details, but I have come across some Windows programs that didn't like the "/" being used where they wanted to see "" instead. I guess you could try it and see, but there's no guarantee it will always work that way, either...
Gilbert
On 12/12/2016 1:57 PM, Kevin McGregor wrote:
Ugh. Even under Windows, doesn't
$cmd = "./psexec.exe //" . $server_name
work the same? Is there any need to use backslashes here?
On Mon, Dec 12, 2016 at 1:53 PM, Gilbert E. Detillieux <gedetil@cs.umanitoba.ca mailto:gedetil@cs.umanitoba.ca> wrote:
Yup, makes sense now... After this line... $cmd = "./psexec.exe \\\\\\\\" . $server_name ... the cmd variable will contain "./psexec.exe \\\\server" (4 backslashes. On running this line... my $output = `$cmd` ... the shell will see "./psexec.exe \\\\server", and the command will see (after shell quote processing) argv[1] set to "\\server". Each level of "\" escape processing requires that you double the number of "\" characters entered to get one through. If you want to end up with 2, after 2 levels, you need 8. Gilbert On 12/12/2016 1:43 PM, Kevin McGregor wrote: I should add that this gets run immediately after via my $output = `$cmd` if that makes any difference. On Mon, Dec 12, 2016 at 1:40 PM, Kevin McGregor <kevin.a.mcgregor@gmail.com <mailto:kevin.a.mcgregor@gmail.com> <mailto:kevin.a.mcgregor@gmail.com <mailto:kevin.a.mcgregor@gmail.com>>> wrote: I'm trying to decipher some Perl code which runs on a Windows server, and I ran into this: $cmd = "./psexec.exe \\\\\\\\" . $server_name I think the idea is to end up with ./psexec.exe \\server but WTF eight backslashes? Does that make any sense? If so, can someone ELI5? Kevin
..... work the same? Is there any need to use backslashes here?
I always operate on the principle "if in doubt, escape it (i.e., backslash it)". Why spend time researching the bare minimum of escaping/backslashing needed, when you can be safer as well as pre-empt future backslashing requirements (if additional characters become special). This also makes the code more readable (yeah!).
I primarily apply this principle in regular expressions, but it is sensible here too.
Hartmut W Sager - Tel +1-204-339-8331, +1-204-515-1701, +1-204-515-1700, +1-810-471-4600
On 12 December 2016 at 13:57, Kevin McGregor kevin.a.mcgregor@gmail.com wrote:
Ugh. Even under Windows, doesn't
$cmd = "./psexec.exe //" . $server_name
work the same? Is there any need to use backslashes here?
On Mon, Dec 12, 2016 at 1:53 PM, Gilbert E. Detillieux < gedetil@cs.umanitoba.ca> wrote:
Yup, makes sense now...
After this line...
$cmd = "./psexec.exe \\\\" . $server_name
... the cmd variable will contain "./psexec.exe \\server" (4 backslashes. On running this line...
my $output = `$cmd`
... the shell will see "./psexec.exe \\server", and the command will see (after shell quote processing) argv[1] set to "\server".
Each level of "" escape processing requires that you double the number of "" characters entered to get one through. If you want to end up with 2, after 2 levels, you need 8.
Gilbert
On 12/12/2016 1:43 PM, Kevin McGregor wrote:
I should add that this gets run immediately after via
my $output = `$cmd`
if that makes any difference.
On Mon, Dec 12, 2016 at 1:40 PM, Kevin McGregor <kevin.a.mcgregor@gmail.com mailto:kevin.a.mcgregor@gmail.com> wrote:
I'm trying to decipher some Perl code which runs on a Windows server, and I ran into this: $cmd = "./psexec.exe \\\\\\\\" . $server_name I think the idea is to end up with ./psexec.exe \\server but WTF eight backslashes? Does that make any sense? If so, can someone ELI5? Kevin
-- Gilbert E. Detillieux E-mail: gedetil@cs.umanitoba.ca Dept. of Computer Science Web: http://www.cs.umanitoba.ca/~ge detil/ University of Manitoba Phone: (204)474-8161 Winnipeg MB CANADA R3T 2N2 Fax: (204)474-7609 _______________________________________________ Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable