瀏覽代碼

On Windows invoke plugins using cmd.exe

This will find .bat files as well as .exe.

Only affects the case when plugins are invoked from PATH.

This does not change behaviour when compiled under Cygwin..
Sigurd Meldgaard 7 年之前
父節點
當前提交
4e5ae963e8
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      src/google/protobuf/compiler/subprocess.cc

+ 5 - 4
src/google/protobuf/compiler/subprocess.cc

@@ -124,14 +124,15 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
                       << Win32ErrorMessage(GetLastError());
                       << Win32ErrorMessage(GetLastError());
   }
   }
 
 
-  // CreateProcess() mutates its second parameter.  WTF?
-  char* name_copy = portable_strdup(program.c_str());
+  // Invoking cmd.exe allows for '.bat' files from the path as well as '.exe'.
+  // Using a malloc'ed string because CreateProcess() can mutate its second parameter.  (WTF).
+  char *command_line =  portable_strdup(("cmd.exe /c \"" + program + "\"").c_str());
 
 
   // Create the process.
   // Create the process.
   PROCESS_INFORMATION process_info;
   PROCESS_INFORMATION process_info;
 
 
   if (CreateProcessA((search_mode == SEARCH_PATH) ? NULL : program.c_str(),
   if (CreateProcessA((search_mode == SEARCH_PATH) ? NULL : program.c_str(),
-                     (search_mode == SEARCH_PATH) ? name_copy : NULL,
+                     (search_mode == SEARCH_PATH) ? command_line : NULL,
                      NULL,  // process security attributes
                      NULL,  // process security attributes
                      NULL,  // thread security attributes
                      NULL,  // thread security attributes
                      TRUE,  // inherit handles?
                      TRUE,  // inherit handles?
@@ -152,7 +153,7 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
 
 
   CloseHandleOrDie(stdin_pipe_read);
   CloseHandleOrDie(stdin_pipe_read);
   CloseHandleOrDie(stdout_pipe_write);
   CloseHandleOrDie(stdout_pipe_write);
-  free(name_copy);
+  free(command_line);
 }
 }
 
 
 bool Subprocess::Communicate(const Message& input, Message* output,
 bool Subprocess::Communicate(const Message& input, Message* output,