Skip to content

Commit

Permalink
Improve quoting behavior when launching procs with cmd.exe
Browse files Browse the repository at this point in the history
Using /S and quotes is better than no S and parens because the parens can get tripped up when > operator is used (since > has higher precedence than parens)
  • Loading branch information
jcheng5 committed Dec 29, 2011
1 parent 06d432e commit 041b8ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cpp/core/system/Win32ChildProcess.cpp
Expand Up @@ -261,8 +261,9 @@ void ChildProcess::init(const std::string& command,
const ProcessOptions& options)
{
exe_ = findOnPath("cmd.exe");
args_.push_back("/S");
args_.push_back("/C");
args_.push_back("(" + command + ")");
args_.push_back("\"" + command + "\"");
options_ = options;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/session/consoleio/ConsoleIOMain.cpp
Expand Up @@ -296,7 +296,7 @@ int main(int argc, char** argv)
::GetCommandLine());

// Use cmd.exe to allow shell commands like "dir" to work properly
cmd = "cmd.exe /c (" + cmd + ")";
cmd = "cmd.exe /s /c \"" + cmd + "\"";
std::vector<char> cmdBuf(cmd.size() + 1, '\0');
cmd.copy(&(cmdBuf[0]), cmd.size());

Expand Down

0 comments on commit 041b8ea

Please sign in to comment.