doc icon indicating copy to clipboard operation
doc copied to clipboard

Proc::Async Example needs to be modified to run on Windows 10

Open mikersanderson opened this issue 8 years ago • 12 comments

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

mikersanderson avatar Aug 16 '17 04:08 mikersanderson

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.

AlexDaniel avatar Aug 16 '17 13:08 AlexDaniel

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.

b2gills avatar Aug 16 '17 14:08 b2gills

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?

mikersanderson avatar Aug 16 '17 14:08 mikersanderson

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.

coke avatar Aug 16 '17 23:08 coke

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.

mikersanderson avatar Aug 17 '17 05:08 mikersanderson

Assigned to @Scimon (can't do it from the pull-down menu since he does not have the commit bit)

JJ avatar Jul 30 '18 08:07 JJ

I'll fork and take a look this evening.

Scimon avatar Jul 30 '18 08:07 Scimon

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.

zoffixznet avatar Jul 30 '18 09:07 zoffixznet

Cheers. I shall behave :)

Scimon avatar Jul 30 '18 09:07 Scimon

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)

ufobat avatar Jan 03 '19 12:01 ufobat

Ping?

JJ avatar Jul 29 '19 06:07 JJ

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.

2colours avatar Aug 05 '23 15:08 2colours