-
Notifications
You must be signed in to change notification settings - Fork 26
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
Command doesn't work as expected when there are double quotes in it #271
Comments
Hi @ProgrammerAL thank you for opening this issue. I tried reproducing this issue on my Mac (changed the dir to @iwahbe Any thoughts here off the top of your head? |
Thanks @mikhailshilkov I believe I'm able to reproduce that error with the Command:
Command"
Again, I only ran this on Windows 11. |
Nothing jumps out to me. This is one of the few providers where we would expect platform specific behavior, so my guess is that |
@ProgrammerAL If you have access to a UNIX interpreter on your machine, do you still get the same result when you specify |
Think I found the reason for this when running on Windows. And it depends on which terminal is used to run the command. Take these two commands as examples when run manually: I use Windows Terminal which I have setup to use PowerShell by default. And with that I'm getting the same output of So the summarize, I guess this is the intended behavior on Windows. This will cause problems to anyone running on Windows, and I don't have a workaround in mind other than to run in PowerShell by default...which I think is installed on all supported Windows machines now. No idea if that's a good idea or not. Side note, @iwahbe I don't have a Unix interpreter on my machine. If you still want, I can install one and try it, but I don't think it matters anymore. |
I believe that the command provider just runs (on windows) pulumi-command/provider/pkg/provider/local/commandOutputs.go Lines 39 to 48 in 18d9626
@ProgrammerAL I think the experiment you already performed satisfies my curiosity. I don't think you need to install a Unix shell. |
@ProgrammerAL @iwahbe Thank you for diagnosing this issue further! It sounds like this is mostly "by design" but can be confusing for Windows users. Do you have suggestions for improvements on the command provider to help with that? |
@iwahbe @mikhailshilkov Since I was still having issues with the Cloudflare Wrangler CLI I spent some more time messing around with this and it looks like the problem is in how the arguments are received by the console app. However I don't know if the fault is on the Pulumi provider or Windows, I'm still experimenting. I created a new C# console application to log the arguments when Pulumi call it. //Launch debugger to view args values when run from Pulumi, remove this to just let the app run to end
Debugger.Launch();
foreach (var arg in args)
{
Console.WriteLine(arg);
} The command I ran from Pulumi is: When running the command manually through the Windows Command Prompt, the C# app receives 5 arguments as expected:
But when run through Pulumi, the app received 8 arguments because the last one is split up based on spaces, and also includes the double quotes:
Honestly I don't have any ideas what to do. This scenario is not expected behavior because it's different from what happens when run manually. But I haven't been able find any kind of workaround. Do you think it's possible there's something in how Go runs apps external processes that could be affecting this? I have no Go experience, so not sure where to even start looking at this. |
@ProgrammerAL Can you try running It's possible that Go is doing something weird when forking into the windows process. It's also possible that I agree that our desired behavior is matching what users see everywhere else. |
@iwahbe Ah good catch, I forgot to use the Version 1:
Version 2:
Version 3:
Version 4:
Version 5:
It seems that versions 2 and 3 work the way I'd expect it to. So that's promising. |
Thanks @ProgrammerAL! That is super helpful! It sounds like the best response is to disambiguate the I don't want to end up re-implementing argument splitting for windows interpreters. I have no idea what semantics Version 2 is using. It seems like it's nesting the double quotes. On a
CC @Frassle @AaronFriel as Windows users. |
From https://pkg.go.dev/os/exec#Command
Also https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd has some info on how to correctly use /c with quotes. But it's tricky getting this right in general. |
What happened?
Running a local command that uses double quotes has a side effect. With the code in the below sample, it ignores the
Dir
property.I noticed another scenario where passing a command with double quotes in it (like wraping a path with a space in it), the double quotes are passed as a literal. And then the command would fail because it doesn't allow double quotes. I couldn't think of an easy example, but if you really need one I can work on creating one.
Example
Below is the code I used. Note that the
CommandArgs.Dir
property is hard coded toc:/temp
. There are 2 lines that create thecommandString
variable. If you run the code with the first one, with the commentThis line works as expected
, it will create a new directory insidec:/temp
. If you instead run the second one, with the commentThis line doesn't work as expected
, it will create a new directory, but it does it at the root path, atc:/
. There is also nothing in the output to show that it was created in the wrong directory.The only real difference between the 2 are what the command is. They are:
mkdir newdir_123
mkdir "newdir_123"
C# Code:
Csproj File:
Below is the output of running
pulumi up
with the first scenario, where it works as expected.Below is the output of running
pulumi up
with the second scenario, where it creates the directory in thec:/
directory. Other than the command string, the outputs are the same.Output of
pulumi about
C:..pulumi-command-bug> pulumi about
running 'dotnet build -nologo .'
Determining projects to restore...
C:\Program Files\dotnet\sdk\7.0.401\NuGet.targets(158,5): warning : No Authorization header detected [C:\temp\pulumi-command-bug\pulumi-command-bug.sln]
All projects are up-to-date for restore.
C:\temp\pulumi-command-bug\pulumi-command-bug.csproj : warning Undefined: No Authorization header detected
pulumi-command-bug -> C:\temp\pulumi-command-bug\bin\Debug\net6.0\pulumi-command-bug.dll
Build succeeded.
C:\Program Files\dotnet\sdk\7.0.401\NuGet.targets(158,5): warning : No Authorization header detected [C:\temp\pulumi-command-bug\pulumi-command-bug.sln]
C:\temp\pulumi-command-bug\pulumi-command-bug.csproj : warning Undefined: No Authorization header detected
2 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.83
'dotnet build -nologo .' completed successfully
CLI
Version 3.83.0
Go Version go1.21.1
Go Compiler gc
Plugins
NAME VERSION
command 0.8.2
dotnet unknown
Host
OS Microsoft Windows 11 Home
Version 10.0.22621 Build 22621
Arch x86_64
This project is written in dotnet: executable='C:\Program Files\dotnet\dotnet.exe' version='7.0.401'
Backend
Name pulumi.com
URL https://app.pulumi.com/ProgrammerAl
User ProgrammerAl
Organizations ProgrammerAl
Dependencies:
NAME VERSION
Pulumi 3.56.2
Pulumi.Command 0.8.2
Pulumi locates its logs in C:\Users\Progr\AppData\Local\Temp by default
warning: Failed to get information about the current stack: No current stack
Additional context
I only ran this on Windows. I do not know what happens when this is run on Linux or Mac OS.
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: