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

fix: correctly escape commands using cmd.exe in Windows #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Guldoman
Copy link
Member

@Guldoman Guldoman commented Feb 9, 2025

No description provided.

table.insert(escaped_commands, '"' .. string.gsub(v, '"', '"""') .. '"')
end
-- The result should be something like `cmd.exe /C ""first" "second" "third""`
options.command = 'cmd.exe /C "' .. table.concat(escaped_commands, " ") .. '"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://ss64.com/nt/cmd.html, you can use /S to simply the quoting.
/S simply strips the first and last quote from the string and treats that as a command,
so you need not bother yourself with yet another layer of escaping.

Otherwise the escaping looks correct to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants