MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / _hx_std_process_run

Function _hx_std_process_run

src/hx/libs/std/Process.cpp:191–335  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

189 </doc>
190**/
191Dynamic _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);

Callers

nothing calls this directly

Calls 13

quoteStringFunction · 0.85
EnterGCFreeZoneFunction · 0.85
ExitGCFreeZoneFunction · 0.85
ThrowFunction · 0.85
closeFunction · 0.85
do_closeFunction · 0.85
utf8_strMethod · 0.80
c_strMethod · 0.80
wchar_strMethod · 0.80
nullClass · 0.50
StringClass · 0.50
createMethod · 0.45

Tested by

no test coverage detected