Skip to content

Instantly share code, notes, and snippets.

@valda
Created November 8, 2010 04:34
Show Gist options
  • Save valda/667381 to your computer and use it in GitHub Desktop.
Save valda/667381 to your computer and use it in GitHub Desktop.
BOSS ブラウザ起動を待たずに終了するパッチ
Index: Helpers.cpp
===================================================================
--- Helpers.cpp (revision 1836)
+++ Helpers.cpp (working copy)
@@ -23,6 +23,9 @@
#include <sys/types.h>
#include <sstream>
+#if _WIN32 || _WIN64
+#include <windows.h>
+#endif
namespace boss {
using namespace std;
@@ -140,7 +143,48 @@
int Launch(const string& filename)
{
+#if _WIN32 || _WIN64
+ ostringstream ss;
+ char buf[MAX_PATH];
+ if (0 < GetEnvironmentVariable("ComSpec", buf, MAX_PATH) && *buf) {
+ ss << buf;
+ } else {
+ OSVERSIONINFO osi;
+ osi.dwOSVersionInfoSize = sizeof(osi);
+ GetVersionEx(&osi);
+ if(VER_PLATFORM_WIN32_WINDOWS == osi.dwPlatformId){
+ ss << "command.com";
+ } else { // VER_PLATFORM_WIN32_NT
+ ss << "cmd.exe";
+ }
+ }
+ ss << " /c start ";
+ string safefilename(filename);
+ algorithm::replace_all(safefilename, "^", "^^");
+ algorithm::replace_all(safefilename, "<", "^<");
+ algorithm::replace_all(safefilename, ">", "^>");
+ algorithm::replace_all(safefilename, "|", "^|");
+ algorithm::replace_all(safefilename, "&", "^&");
+ ss << safefilename;
+ STARTUPINFO si;
+ ZeroMemory(&si,sizeof(si));
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USEFILLATTRIBUTE | STARTF_USECOUNTCHARS | STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+ PROCESS_INFORMATION pi;
+ ZeroMemory(&pi,sizeof(pi));
+ const string &ssstr = ss.str();
+ vector<char> cmdline(ssstr.length() + 1, '\0');
+ copy(ssstr.begin(), ssstr.end(), cmdline.begin()); // CreateProcess requires a non-const cstring.
+ if (::CreateProcess(NULL, &cmdline[0], NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) {
+ ::CloseHandle(pi.hThread);
+ ::CloseHandle(pi.hProcess);
+ return 0;
+ }
+ return -1;
+#else
const string cmd = launcher_cmd + " " + filename;
return ::system(cmd.c_str());
+#endif
}
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment