-
Notifications
You must be signed in to change notification settings - Fork 844
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
Cannot use WSL.exe to invoke Linux commands in PowerShell #5232
Comments
Just figured it out! CMD
(that's a literal ^, not CTRL+) Powershell
|
Thanks for the suggestion @sundhaug92, alas, no cigar |
@bitcrazed I've updated the comment, I forgot we were talking pscore rather than cmd.exe |
Because wsl.exe treats each argv as a separate argument (or command), you can't use "". Because you can't use "" you have to find another way to tell the host-shell (cmd, ps, ...) if any to ignore things like When using C#, you can then get away with something like var pi = new ProcessStartInfo();
pi.FileName = @"C:\Windows\sys" + (IntPtr.Size == 4 ? "native" : "tem32") + @"\wsl.exe"; // Solution for starting 64-bit WSL from a 32-bit process
pi.Arguments = "fortune | cowsay | lolcat";
var p = Process.Start(pi);
p.WaitForExit(); |
Piping is a shell feature. You need to pipe in the syntax of the shell you’re invoking, and invoke the shell explicitly to do that.
|
This is #3284. With But on planet sanity, Duntin's answer is better (same as message). Those ' |
Followed this, but my original question was trying to run multiple commands which works with Notice the error is 'No such file or directory' - it looks like Now look at the craziness of stuff that works and what doesn't: The first thing running Code without quotes around anything sort of works and launches Code: wsl cd /mnt/c/projects/Test/jekyll/help; code . But... although it opens, when it does the new path change is lost. The other commands likely are not working for the same reason - the commands appear to not execute in the same shell context so the bundle command is not found out of that folder context. Running the same thing with quotes doesn't work at all: wsl "cd /mnt/c/projects/Test/jekyll/help; code ." which is sort of the same thing I'm doing in the previous screen shot. wsl cd /mnt/c/projects/Test/jekyll/help; cd; bundle exec jekyll serve; This gets me closer - it looks like both commands execute, but the path is not set from the previous command so BOOM again. Everything explicit seems to be treated as one big command same as the single string: wsl "cd /mnt/c/projects/Test/jekyll/help" "cd" "bundle exec jekyll serve" |
@RickStrahl Try the variant from @DHowett : |
Running
Here
In this one
In this one powershell couldn't find Your scenario would be something like:
|
Thanks @therealkenc. Perfect answer. I completely forgot about invoking sh. Duh. |
@RickStrahl reported this issue in a Twitter conversation with @sundhaug92 and myself, ending here: https://twitter.com/richturn_ms/status/1262885317826113536
Running Win10 x64 with Ubuntu (WSL2) distro with fortune-mod, cowsay, and lolcat installed.
In PowerShell Core x64, invoke simple Linux command, like fortune:
Yay!
Now let's make a cow say it and make it colorful
SAYWHATNOW?
Lolcat is definitely installed:
No! I KNOW lolcat is intalled ...
Perhaps PowerShell is parsing the command-line. Let's quote it so it's just a string.
SRSLY?
Worked example:
So, how DOES one invoke wsl.exe passing an arbitrary command-line script?
The text was updated successfully, but these errors were encountered: