-
-
Notifications
You must be signed in to change notification settings - Fork 864
Fix: Properly handle paths with spaces in generated command #749
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
Conversation
Codecov ReportAttention: Patch coverage is
|
Hi @xiantang, I noticed that the It would be great if you could:
Thank you for your time and assistance! |
looks pipeline is ok now. |
quotedPath := fmt.Sprintf(`"%s"`, path) | ||
|
||
if runtime.GOOS == PlatformWindows { | ||
return fmt.Sprintf(`& %s`, quotedPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not using Windows, what does &
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding &
before the path in quotation marks ("path") is necessary for PowerShell or the Windows command prompt to correctly interpret the path with spaces as a command to execute. Without &
, a path with spaces can be interpreted as a string, not as a command.
Usage examples:
- Running an executable file with spaces in the path:
If the path to the executable file contains spaces, PowerShell will not be able to execute it without&
.
& "C:\Program Files\MyApp\myapp.exe"
- Running commands with arguments:
You can use & to run commands with arguments:
& "C:\Program Files\MyApp\myapp.exe" --arg1 value1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes:
- If the path to an executable file or script is called without
&
, PowerShell interprets it as a string, not as a command. For example:
"C:\Program Files\MyApp\myapp.exe"
Result:
It just returns the string C:\Program Files\MyApp\myapp.exe
, but the command is not executed.
- If the path contains spaces and is not enclosed in quotation marks, PowerShell or the command line will not be able to process it correctly. For example:
C:\Program Files\MyApp\myapp.exe
Result:
PowerShell will try to interpret C:\Program
As a command, eh Files\MyApp\myapp.exe
as an argument, which will lead to an error.
- I ran the tests manually locally on Windows, then the coverage reaches 100% for the
formatPath()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
& "..."
syntax).Changes:
formatPath()
function inrunner/util.go
to:formatPath()
into command generation inrunner/engine.go
.runner/util_test.go
covering:Testing:
Notes:
C:\Program Files\app.exe
or/usr/local/my app/main
execute correctly.Closes #666