process_run : cmd:string -> args:string array -> 'process Start a process using a command. When args is not null, cmd and args will be auto-quoted/escaped. If no auto-quoting/escaping is desired, you should append necessary arguments to cmd as if it is inputted to the shell directly, and pass null to args. inShowParam = only for windows, SHOW_* from "ShowWindow" functi
| 189 | </doc> |
| 190 | **/ |
| 191 | Dynamic _hx_std_process_run( String cmd, Array<String> vargs, int inShowParam ) |
| 192 | { |
| 193 | #if defined(APPLETV) || defined(HX_APPLEWATCH) |
| 194 | return null(); |
| 195 | |
| 196 | #else |
| 197 | vprocess *p = 0; |
| 198 | bool isRaw = !vargs.mPtr; |
| 199 | |
| 200 | #ifdef NEKO_WINDOWS |
| 201 | { |
| 202 | SECURITY_ATTRIBUTES sattr; |
| 203 | STARTUPINFOW sinf; |
| 204 | HANDLE proc = GetCurrentProcess(); |
| 205 | HANDLE oread,eread,iwrite; |
| 206 | // creates commandline |
| 207 | String b; |
| 208 | if (isRaw) |
| 209 | { |
| 210 | b = HX_CSTRING("\""); |
| 211 | const char* cmdexe = getenv("COMSPEC"); |
| 212 | if (!cmdexe) cmdexe = "cmd.exe"; |
| 213 | b += String(cmdexe) + HX_CSTRING("\" /C \"") + cmd + HX_CSTRING("\""); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | b = HX_CSTRING("\"") + cmd + HX_CSTRING("\""); |
| 218 | |
| 219 | for(int i=0;i<vargs->length;i++) |
| 220 | { |
| 221 | b += HX_CSTRING(" \""); |
| 222 | if (vargs[i].length) |
| 223 | b += quoteString(vargs[i]); |
| 224 | b += HX_CSTRING("\""); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | const wchar_t *name = b.__WCStr(); |
| 229 | |
| 230 | hx::EnterGCFreeZone(); |
| 231 | // startup process |
| 232 | sattr.nLength = sizeof(sattr); |
| 233 | sattr.bInheritHandle = TRUE; |
| 234 | sattr.lpSecurityDescriptor = NULL; |
| 235 | memset(&sinf,0,sizeof(sinf)); |
| 236 | sinf.cb = sizeof(sinf); |
| 237 | sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; |
| 238 | sinf.wShowWindow = inShowParam; |
| 239 | CreatePipe(&oread,&sinf.hStdOutput,&sattr,0); |
| 240 | CreatePipe(&eread,&sinf.hStdError,&sattr,0); |
| 241 | CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0); |
| 242 | |
| 243 | HANDLE procOread,procEread,procIwrite; |
| 244 | |
| 245 | DuplicateHandle(proc,oread,proc,&procOread,0,FALSE,DUPLICATE_SAME_ACCESS); |
| 246 | DuplicateHandle(proc,eread,proc,&procEread,0,FALSE,DUPLICATE_SAME_ACCESS); |
| 247 | DuplicateHandle(proc,iwrite,proc,&procIwrite,0,FALSE,DUPLICATE_SAME_ACCESS); |
| 248 | CloseHandle(oread); |
nothing calls this directly
no test coverage detected