Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mikersanderson opened this issue Aug 16, 2017 · 12 comments
Open

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

mikersanderson opened this issue Aug 16, 2017 · 12 comments
Labels
docs Documentation issue (primary issue type) update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.

Comments

@mikersanderson
Copy link

mikersanderson commented Aug 16, 2017

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

@AlexDaniel
Copy link
Member

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.

@b2gills
Copy link
Contributor

b2gills commented Aug 16, 2017

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.

@mikersanderson
Copy link
Author

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?

@coke
Copy link
Collaborator

coke commented Aug 16, 2017

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.

@mikersanderson
Copy link
Author

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.

@coke coke added the docs Documentation issue (primary issue type) label Aug 19, 2017
@JJ JJ added the update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc. label May 14, 2018
@JJ JJ self-assigned this May 14, 2018
@JJ JJ removed their assignment Jul 30, 2018
@JJ
Copy link
Contributor

JJ commented Jul 30, 2018

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

@Scimon
Copy link
Contributor

Scimon commented Jul 30, 2018

I'll fork and take a look this evening.

@zoffixznet
Copy link
Contributor

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.

@Scimon
Copy link
Contributor

Scimon commented Jul 30, 2018

Cheers. I shall behave :)

@Scimon Scimon self-assigned this Jul 31, 2018
@ufobat
Copy link
Contributor

ufobat commented Jan 3, 2019

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)

@JJ
Copy link
Contributor

JJ commented Jul 29, 2019

Ping?

@coke coke assigned coke and unassigned Scimon Mar 1, 2023
@coke coke added this to the 2023-Quarter 2 milestone Mar 1, 2023
@coke coke modified the milestones: 2023-Quarter 2, 2023-Quarter 3 Jul 12, 2023
@2colours
Copy link
Contributor

2colours commented Aug 5, 2023

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.

@coke coke removed their assignment Aug 15, 2023
@coke coke modified the milestones: 2023-Quarter 3, 2023-Quarter 4 Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.
Projects
None yet
Development

No branches or pull requests

9 participants