Raku: what is the syntax for shell calls with spaces?

Viewed 238

Edit: I reported this as a bug to Raku: qqx, shell not operating quotes properly https://github.com/rakudo/rakudo/issues/3518

and one of the administrators referred me to How should Proc::Async.new, run and shell call cmd.exe? https://github.com/Raku/problem-solving/issues/20

which does sound exactly like what is occurring, especially the "It's not possible to escape spaces using ^." part.

If anyone comes up with a workaround, I would appreciate it.

Windows 7, and Windows 10-1909

Rakudo Star version 2019.03.1

How do I code this command in Raku?

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

The big bug-a-boo is that the file name has a space in it and Windows required double quotes around it. Single quotes crash.

I can not get either of these two to work with a file name with a space in it. fsutil either sees two parameters or one parameter where the name actually contains double quotes:

my @Result = qqx { C:/Windows/System32/fsutil.exe usn readdata "$FileName" }.lines;
for @Result -> $Line  { say $Line; };

my $proc=run( "dir", "$FileName", :out );
my @RtnStr  = $proc.out.slurp-rest.lines; 
for @RtnStr -> $Line { say $Line; }

Many thanks, -T

Edit: added Windows 10-1909 to the fray

Edit: no symptom change with "shell" command:

@Result = shell( "C:/Windows/System32/fsutil.exe usn readdata \"$FileName\"" ).lines;
for @Result -> $Line  { say $Line; };

Usage : fsutil usn readData <filename>
   Eg : fsutil usn readData C:\Temp\sample.txt

@Result = shell( "C:/Windows/System32/fsutil.exe usn readdata \"$FileName\"" );
for @Result -> $Line  { say $Line; };

Exit with:

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\"",))

Note the "exitcode => 1" and the last parameter with the back slashes in it

Edit: using the single quote method:

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

results in the same error:

Usage : fsutil usn readData <filename>
   Eg : fsutil usn readData C:\Temp\sample.txt
Error:  The filename, directory name, or volume label syntax is incorrect.
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\"",))
4 Answers

There's shell:

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

That's going to be the same here and there. It will also use existing common shell for any operating system. You can also use variables, provided you escape quotes destined for the shell:

my $words = "two words"
shell("echo \"$words\"")

or

shell "echo \""~ $words ~ "\""

Hello i've been testing Perl6 now Raku from windows 7 to windows 10. i dont know if this solves the problem but for me it works : in a file.rk or file.pl write :

shell "fsutil fsinfo drives & pause";

both fsutil and pause work.

Maybe this will help:

You can try escaping the space in the file path with ^

Example:

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

I have a workaround for anyone stopped because of this bug: I am taking advantage of the Windows build in batch programming language:

my $PathIAm = $?FILE;
( my $IAm = $PathIAm ) ~~ s| .* "/" ||;

my Str $BatFile = $PathIAm ~ ".bat";
$BatFile ~~ s:global| '\\' |/|;

my Str $OS = $*KERNEL.name;
if not $OS eq "win32" { 
   say "Sorry, $IAm only work in Windows.";
   exit; }
( $IAm = $PathIAm ) ~~ s| .* '\\' ||;

my Str $CmdStr = 
   Q[@echo off] ~ "\n" ~
   Q[C:\Windows\System32\fsutil.exe usn readdata ] ~
   Q["] ~ $FileName ~ Q["] ~ "\n";
# say $CmdStr;


spurt( $BatFile, $CmdStr );
say qqx { $BatFile };

Result:

C:\NtUtil>raku k:\Windows\NtUtil\FileAttributes.pl6 "Test 1"

Major Version    : 0x3
Minor Version    : 0x0
FileRef#         : 0x00000000000000000058000000000340
Parent FileRef#  : 0x00000000000000000013000000000eb9
Usn              : 0x00000000711dab68
Time Stamp       : 0x0000000000000000 12:00:00 AM 1/1/1601
Reason           : 0x0
Source Info      : 0x0
Security Id      : 0x0
File Attributes  : 0x20
File Name Length : 0xc
File Name Offset : 0x4c
Related