I'm converting a Unix Perl script to run on Windows. I'm having a problem with paths that have spaces in them:
open (IN, "| C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysql.exe -u root -ppwd") or die "$!";
The code above throws the following error:
'C:\Program' is not recognized as an internal or external command,
I tried wrapping in escaped \"
like this:
open (IN, "| \"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysql.exe -u root -ppwd\"") or die "$!";
But no joy. How do I handle paths with spaces?
I'm using ActiveState v5.10.0 built for MSWin32-x86-multi-thread.
You are quoting the entire command, including the command-line arguments. You should have put your second escaped quote after the mysql.exe
:
open (IN, "| \"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysql.exe\" -u root -ppwd") or die "$!";
You might also be interested in the qq()
and q()
operators, which allow you to use delimiters other than quotation marks to delimit strings. They are very helpful when you want to quote a string that includes quotes:
qq[| "C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysql.exe" -u root -ppwd]
Also, Perl will happily handle the correct path separator for command names (but not always for command arguments, so beware):
qq[| "C:/Program Files/MySQL/MySQL Server 5.1/bin/mysql.exe" -u root -ppwd]
(And since this example doesn't need any interpolation, you could have used single-quotes or the q()
construction:
'| "C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysql.exe" -u root -ppwd'
)
It's Perl, so there are a 1000 ways (as you'll see), One way (escape the spaces)
open (IN, "| C:\\Program\ Files\\MySQL\\MySQL\ Server\ 5.1\\bin\\mysql.exe -u root -ppwd") or die "$!";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With