doc
doc copied to clipboard
Proc::Async Example needs to be modified to run on Windows 10
On page: https://docs.perl6.org/type/Proc::Async
The first example:
my $proc = Proc::Async.new('echo', 'foo', 'bar');
# subscribe to new output from out and err handles:
$proc.stdout.tap(-> $v { print "Output: $v" }, quit => { say 'caught exception ' ~ .^name });
$proc.stderr.tap(-> $v { print "Error: $v" });
say "Starting...";
my $promise = $proc.start;
# wait for the external program to terminate
await $promise;
say "Done.";
Will not run properly on Windows. Apparently this is because in Windows, echo is a function of the executable cmd.exe.
So, to make this work on Windows, one has to change the line:
my $proc = Proc::Async.new('echo', 'foo', 'bar');
to:
my $proc = Proc::Adync.new('cmd.exe', '/c', 'echo foo bar');
Then it will run properly.
It would be great if the example could be updated to mention this
Is there any other way to do it? These two examples are completely different. In the first one you start a process in a reasonably safe manner, but in your second example you are effectively shelling out. Practically that's run vs shell. I'd rather not advertise this kind of usage as normal.
It could state that it directly calls an executable and that echo is actually a command built into cmd.exe rather than a separate executable on Windows. (also dir)
It could also tell you how to get around that by shelling out to the command processor cmd.exe and calling echo in that, or add an echo.exe to the path. (There are a variety of sources for an echo.exe)
A link to Proc and a short note about run and shell for simple uses might be warranted.
I think that what b2gills is suggesting would be good ... for me, as someone new to Perl that more or less has to use Windows, it was very frustrating to try the example and not have it work. So having it state that it needs to be an executable would be helpful. In addition to that, perhaps it would be good to change the example to something that would work on multiple platforms? Windows has nslookup.exe , maybe something like 'nslookup.exe', '127.0.0.1' would work everywhere?
Having multiple examples, one for windows and one for *nix systems is fine, IMO - For examples that require interaction with the OS, we don't need a single example that works the same everywhere.
Sure, I think that would be fine too ... the big thing is to state that up front in a clear manner. Now I realize that it says "Proc::Async allows you to run external commands asynchronously" but when I was running through things, and things weren't working, I didn't grasp that echo wasn't an external command on windows. I have Perl 6 Fundamentals by Lentz and it's not really clear in there, and I have Perl6 at a Glance by Shitov and Proc::Async isn't covered at all in there ... I really did try to understand what was happening, but eventually had to go to ask on the irc channel where I got help. I'm personally struggling quite a bit with Perl 6 and need all the help I can get.
Assigned to @Scimon (can't do it from the pull-down menu since he does not have the commit bit)
I'll fork and take a look this evening.
I'll fork
I sent you an invite to perl6 org. You can accept it on https://github.com/perl6 and then you'll have direct access to this repo.
Cheers. I shall behave :)
FYI: You do have this kind of "windows problem" in various places or modules, even if the command you want to invoke is not a build-in of the cmd shell. (I've got the feeling that people on windows run into that issue over and over again)
Ping?
Two examples for the two fundamental platform types is okay, I think even a big fat disclaimer about process calls being heavily platform-dependent would do. Honestly, picking up the burden of explaining platform-specific things about various shell interfaces for different OSes seems above the paycheck of Raku documentation.