in reply to Problem running shell command from Perl
Were I to hazard a guess, I would say it is the fact that the Windows CMD prompt does not understand '/' as a path separator; instead, it uses '\' (which most things with a *nix background -- including C and perl -- use as an escape character). In order to include a '\' in a string, you would need to use "\\", or a '\' in a single-quoted string. You can also use the q or qq operators as a way to quote the string. ('q//' is a way to represent a single-quoted string, and 'qq//' a double-quoted string.)
# Replace assignment with this. # 'q//' treats as a single-quoted string, which does not try to # interpolate characters. As a result, the double-quotes in # the command do not require escaping. Here I used the '/' as # the delimiter for the single-quoting 'q', but could be other # characters depending on what is needed in the string. I also # used the '.' to concatenate the string, allowing it to be # written across multiple lines so the spaces between parameters # were obvious. my $cmd = q/fsutil/ # command . q/ / . q/file/ # parameter 1 . q/ / . q/setShortName/ # parameter 2 . q/ / . q/"C:\Users\James\Music\國語懷念&# +32769;歌 Vol. 2"/ # parameter 3 . q/ / . q/"Vol2~00A"/; # parameter 4 # The double-quotes in parameter 3 are necessary # due to the spaces within the file name. # Continue remainder of code as before
Hope that helps.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Problem running shell command from Perl
by CrashBlossom (Beadle) on Jun 20, 2023 at 02:58 UTC | |
by atcroft (Abbot) on Jun 20, 2023 at 06:46 UTC | |
by CrashBlossom (Beadle) on Jun 20, 2023 at 17:26 UTC |