From 0f655bc53c97344b38e7fbbee4ba8cf23d7cc63d Mon Sep 17 00:00:00 2001 From: Justin Espedal Date: Fri, 17 Sep 2021 12:43:54 +0900 Subject: [PATCH] Avoid using system shell to start processes This relates to https://github.com/HaxeFoundation/haxe/issues/10389 This change allows Haxe's basic build tooling to be used even when the system shell is unavailable. `Sys.command` runs processes through the system shell. The 2-argument form of `new Process`, on the other hand, starts processes without going through the shell. --- src/haxelib/client/Main.hx | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/haxelib/client/Main.hx b/src/haxelib/client/Main.hx index 09de2eb4b..85a327e4b 100644 --- a/src/haxelib/client/Main.hx +++ b/src/haxelib/client/Main.hx @@ -1660,6 +1660,37 @@ class Main { } static var __haxeVersion:SemVer; + function createProcess(command:String, args:Array) + { + var process = new Process(command, args); + + var waiting = true; + + while (waiting) + { + try + { + Sys.println(process.stdout.readLine()); + } + catch (e:haxe.io.Eof) + { + waiting = false; + } + } + + var error = process.stderr.readAll().toString(); + var result = process.exitCode(); + + if (error != "") + { + Sys.println(error); + } + + process.close(); + + return result; + } + function doRun( rep:String, project:String, version:String ) { var pdir = rep + Data.safe(project); if( !FileSystem.exists(pdir) ) @@ -1695,7 +1726,7 @@ class Main { Sys.putEnv("HAXELIB_RUN", "1"); Sys.putEnv("HAXELIB_RUN_NAME", project); var cmd = callArgs.shift(); - Sys.exit(Sys.command(cmd, callArgs)); + Sys.exit(createProcess(cmd, callArgs)); } function runScriptArgs(project:String, main:String, dependencies:Dependencies):Array {