Skip to content

Commit 4dfedca

Browse files
author
Daniel Kroening
committed
on Windows, empty shell arguments require quotes
Unix-like OSs pass an array of strings to processes as the command line arguments. Empty arguments do not require special treatment. By contrast, Windows uses a single string to pass all arguments to the process. The process parses the string to construct argv[]. To pass an empty argument, quotes are required. Note that this is unrelated to any additional parsing a shell might perform.
1 parent c7bb936 commit 4dfedca

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/util/run.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ static fdt stdio_redirection(int fd, const std::string &file)
165165
// https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
166166
std::wstring quote_windows_arg(const std::wstring &src)
167167
{
168-
if(src.find_first_of(L" \t\n\v\"") == src.npos)
168+
// note that an empty argument requires quotes
169+
if(src.find_first_of(L" \t\n\v\"") == src.npos && !src.empty())
169170
return src;
170171

171172
std::wstring result = L"\"";

0 commit comments

Comments
 (0)