فهرست منبع

Changed executeExternalCommand on Windows to use popen and return resulting output

Ivan Safrin 12 سال پیش
والد
کامیت
f6db02c499
2فایلهای تغییر یافته به همراه16 افزوده شده و 22 حذف شده
  1. 15 21
      Core/Contents/Source/PolyWinCore.cpp
  2. 1 1
      IDE/Contents/Source/PolycodeToolLauncher.cpp

+ 15 - 21
Core/Contents/Source/PolyWinCore.cpp

@@ -1024,27 +1024,21 @@ String Win32Core::executeExternalCommand(String command,  String args, String in
 		execInDirectory = defaultWorkingDirectory;
 	}
 
-	SHELLEXECUTEINFO lpExecInfo;
-      lpExecInfo.cbSize  = sizeof(SHELLEXECUTEINFO);
-      lpExecInfo.lpFile = command.getWDataWithEncoding(String::ENCODING_UTF8);
-	lpExecInfo.fMask=SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS ;     
-      lpExecInfo.hwnd = NULL;  
-      lpExecInfo.lpVerb = L"open"; // to open  program
-      lpExecInfo.lpParameters =  args.getWDataWithEncoding(String::ENCODING_UTF8); //  file name as an argument
-      lpExecInfo.lpDirectory = execInDirectory.getWDataWithEncoding(String::ENCODING_UTF8);   
-      lpExecInfo.nShow = SW_SHOW ;  // show command prompt with normal window size 
-      lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ;   //WINSHELLAPI BOOL WINAPI result;
-      ShellExecuteEx(&lpExecInfo);
-    
- 
-      //wait until a file is finished printing
-      if(lpExecInfo.hProcess !=NULL)
-      {
-        ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
-        ::CloseHandle(lpExecInfo.hProcess);
-      }
-
-	  return "";
+	String cmdString = "cd \""+execInDirectory+"\" & "+command+" "+args;
+
+	char   psBuffer[128];
+	FILE   *pPipe;
+	if((pPipe = _popen(cmdString.c_str(), "rt" )) == NULL) {
+		return "";
+	}
+
+	String retString;
+	while(fgets(psBuffer, 128, pPipe)) {
+		retString += String(psBuffer);
+   }
+
+	_pclose(pPipe);
+	return retString;
 }
 
 String Win32Core::openFolderPicker()  {

+ 1 - 1
IDE/Contents/Source/PolycodeToolLauncher.cpp

@@ -53,7 +53,7 @@ void PolycodeRunner::runThread() {
 	String inFolder = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources";
 	String args = polyappPath;
 #elif defined _WINDOWS
-	String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.exe";
+	String command = "\""+polycodeBasePath+"/Standalone/Player/PolycodePlayer.exe\"";
 	String args = polyappPath;
 	String inFolder = polycodeBasePath+"/Standalone/Player";
 #else