From b6a3c834946ee106722fa94e4c247f4358b4e30f Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 19 Jan 2015 18:42:37 +0000 Subject: [PATCH] Core: LocalProcess with args - win32 implementation git-svn-id: svn://ultimatepp.org/upp/trunk@8068 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/LocalProcess.cpp | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/uppsrc/Core/LocalProcess.cpp b/uppsrc/Core/LocalProcess.cpp index 8cd88c91d..e5c8b90ae 100644 --- a/uppsrc/Core/LocalProcess.cpp +++ b/uppsrc/Core/LocalProcess.cpp @@ -110,6 +110,43 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool si.hStdInput = hInputRead; si.hStdOutput = hOutputWrite; si.hStdError = hErrorWrite; + String cmdh; + if(arg) { + cmdh = command; + for(int i = 0; i < arg->GetCount(); i++) { + cmdh << ' '; + String argument = (*arg)[i]; + if(argument.GetCount() && argument.FindFirstOf(" \t\n\v\"") < 0) + cmdh << argument; + else { + cmdh << '\"'; + const char *s = argument; + for(;;) { + int num_backslashes = 0; + while(*s == '\\') { + s++; + num_backslashes++; + } + if(*s == '\0') { + cmdh.Cat('\\', 2 * num_backslashes); + break; + } + else + if(*s == '\"') { + cmdh.Cat('\\', 2 * num_backslashes + 1); + cmdh << '\"'; + } + else { + cmdh.Cat('\\', num_backslashes); + cmdh.Cat(*s); + } + s++; + } + cmdh << '\"'; + } + } + command = cmdh; + } int n = (int)strlen(command) + 1; Buffer cmd(n); memcpy(cmd, command, n);