windows Raku:shell调用中带空格的语法是什么?

zi8p0yeb  于 2023-10-22  发布在  Windows
关注(0)|答案(5)|浏览(131)

编辑:我将此作为一个bug报告给了Raku:qqx,shell不能正确操作报价https://github.com/rakudo/rakudo/issues/3518
其中一个管理员向我推荐了How should Proc::Async.new,run and shell call cmd.exe?https://github.com/Raku/problem-solving/issues/20
这听起来确实像是正在发生的事情,特别是“不可能使用^.来转义空格”这部分。
如果有人想出一个变通办法,我会很感激的。
Windows 7和Windows 10-1909
Rakudo星星版本2019.03.1
如何在Raku中编写此命令?

  1. fsutil usn readdata "C:/NtUtil/test 1"

最大的问题是文件名中有一个空格,Windows要求在它周围加上双引号。单引号崩溃。
我不能让这两个工作与一个文件名与一个空格在它。fsutil要么看到两个参数,要么看到一个参数,其中名称实际上包含双引号:

  1. my @Result = qqx { C:/Windows/System32/fsutil.exe usn readdata "$FileName" }.lines;
  2. for @Result -> $Line { say $Line; };
  3. my $proc=run( "dir", "$FileName", :out );
  4. my @RtnStr = $proc.out.slurp-rest.lines;
  5. for @RtnStr -> $Line { say $Line; }

非常感谢,T
编辑:将Windows 10-1909添加到战斗中
编辑:使用“shell”命令时症状无变化:

  1. @Result = shell( "C:/Windows/System32/fsutil.exe usn readdata \"$FileName\"" ).lines;
  2. for @Result -> $Line { say $Line; };
  3. Usage : fsutil usn readData <filename>
  4. Eg : fsutil usn readData C:\Temp\sample.txt
  5. @Result = shell( "C:/Windows/System32/fsutil.exe usn readdata \"$FileName\"" );
  6. for @Result -> $Line { say $Line; };

退出:

  1. Proc.new(in => IO::Pipe, out => IO::Pipe, err => IO::Pipe, exitcode => 1, signal => 0, pid => 1728, command => ("C:/Windows/System32/fsutil.exe usn readdata \"C:/NtUtil/test 1\"",))

注意“exitcode => 1”和最后一个带有反斜杠的参数
编辑:使用单引号方法:

  1. @Result = shell( 'C:/Windows/System32/fsutil.exe usn readdata "$FileName"' );

导致相同的错误:

  1. Usage : fsutil usn readData <filename>
  2. Eg : fsutil usn readData C:\Temp\sample.txt
  3. Error: The filename, directory name, or volume label syntax is incorrect.
  4. Proc.new(in => IO::Pipe, out => IO::Pipe, err => IO::Pipe, exitcode => 1, signal => 0, pid => 1192, command => ("C:/Windows/System32/fsutil.exe usn readdata \"\$FileName\"",))
kr98yfug

kr98yfug1#

shell

  1. shell('echo "two words"'); # OUTPUT: «two words»

这里和那里都是一样的。它还将使用任何操作系统的现有通用shell。你也可以使用变量,前提是你要给shell加转义引号:

  1. my $words = "two words"
  2. shell("echo \"$words\"")

  1. shell "echo \""~ $words ~ "\""
qlckcl4x

qlckcl4x2#

你好,我一直在测试Perl 6现在Raku从Windows 7到Windows 10。我不知道这是否解决了问题,但对我来说,这是有效的:在文件.rk或file.pl中写入:
shell“fsutil fsinfo drives & pause”;
fsutil和pause都可以工作。

siotufzp

siotufzp3#

也许这会有帮助:
您可以尝试使用^转义文件路径中的空格
范例:

  1. c:\Documents^ and^ Settings\a.bat
kcugc4gi

kcugc4gi4#

我有一个解决方案,任何人停止,因为这个错误:我正在利用批处理编程语言中的Windows构建:

  1. my $PathIAm = $?FILE;
  2. ( my $IAm = $PathIAm ) ~~ s| .* "/" ||;
  3. my Str $BatFile = $PathIAm ~ ".bat";
  4. $BatFile ~~ s:global| '\\' |/|;
  5. my Str $OS = $*KERNEL.name;
  6. if not $OS eq "win32" {
  7. say "Sorry, $IAm only work in Windows.";
  8. exit; }
  9. ( $IAm = $PathIAm ) ~~ s| .* '\\' ||;
  10. my Str $CmdStr =
  11. Q[@echo off] ~ "\n" ~
  12. Q[C:\Windows\System32\fsutil.exe usn readdata ] ~
  13. Q["] ~ $FileName ~ Q["] ~ "\n";
  14. # say $CmdStr;
  15. spurt( $BatFile, $CmdStr );
  16. say qqx { $BatFile };

测试结果:

  1. C:\NtUtil>raku k:\Windows\NtUtil\FileAttributes.pl6 "Test 1"
  2. Major Version : 0x3
  3. Minor Version : 0x0
  4. FileRef# : 0x00000000000000000058000000000340
  5. Parent FileRef# : 0x00000000000000000013000000000eb9
  6. Usn : 0x00000000711dab68
  7. Time Stamp : 0x0000000000000000 12:00:00 AM 1/1/1601
  8. Reason : 0x0
  9. Source Info : 0x0
  10. Security Id : 0x0
  11. File Attributes : 0x20
  12. File Name Length : 0xc
  13. File Name Offset : 0x4c
展开查看全部
sdnqo3pr

sdnqo3pr5#

我搞砸了很长时间;我差点就跟拉库分手了最后用powershell写了这个:希望这对某人有帮助。

  1. my $vscode = q/C:\Users\pb\AppData\Local\Programs\Microsoft VS Code\Code.exe/;
  2. my $file = q/C:\temp\Notes 2023-09.md/;
  3. qqx{echo \& \"$vscode\" \"$file\"};

编辑:回答原始问题

  1. my $fsutil = q/C:\Windows\System32\fsutil.exe/;
  2. my $file = q/C:\temp\Notes 2023-09.md/;
  3. say qqx{echo \& \"$fsutil\" usn readdata \"$file\"};

相关问题