Browse Source

added "detached" flag from sys.io.Process creation

Nicolas Cannasse 8 years ago
parent
commit
fae543b5f9

+ 2 - 1
std/cpp/_std/sys/io/Process.hx

@@ -93,7 +93,8 @@ class Process {
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
 
-	public function new( cmd : String, ?args : Array<String> ) : Void {
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void {
+		if( detached ) throw "Detached process is not supported on this platform";
 		p = try NativeProcess.process_run(cmd,args) catch( e : Dynamic ) throw "Process creation failure : "+cmd;
 		stdin = new Stdin(p);
 		stdout = new Stdout(p,true);

+ 2 - 1
std/cs/_std/sys/io/Process.hx

@@ -35,8 +35,9 @@ class Process {
 
 	private var native:NativeProcess;
 
-	public function new( cmd : String, ?args : Array<String> ) : Void
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void
 	{
+		if( detached ) throw "Detached process is not supported on this platform";
 		this.native = createNativeProcess(cmd, args);
 		native.Start();
 

+ 3 - 3
std/hl/_std/sys/io/Process.hx

@@ -93,7 +93,7 @@ private class Stdout extends haxe.io.Input {
 
 	static var isWin = Sys.systemName() == "Windows";
 
-	public function new( cmd : String, ?args : Array<String> ) : Void {
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void {
 		var runCmd = cmd;
 		if( isWin ) {
 			var b = new StringBuf();
@@ -144,7 +144,7 @@ private class Stdout extends haxe.io.Input {
 				for( i in 0...args.length )
 					aargs[i] = Sys.getPath(args[i]);
 			}
-			p = _run(Sys.getPath(runCmd), aargs);
+			p = _run(Sys.getPath(runCmd), aargs, detached);
 		}
 		if( p == null )
 			throw new Sys.SysError("Process creation failure : "+cmd);
@@ -173,7 +173,7 @@ private class Stdout extends haxe.io.Input {
 		_kill(p);
 	}
 
-	@:hlNative("std","process_run")	static function _run( cmd : hl.Bytes, args : hl.NativeArray<hl.Bytes> ) : ProcessHandle { return null; }
+	@:hlNative("std","process_run")	static function _run( cmd : hl.Bytes, args : hl.NativeArray<hl.Bytes>, detached : Bool ) : ProcessHandle { return null; }
 	@:hlNative("std", "process_exit") static function _exit( p : ProcessHandle, running : hl.Ref<Bool> ) : Int { return 0; }
 	@:hlNative("std", "process_pid") static function _pid( p : ProcessHandle ) : Int { return 0; }
 	@:hlNative("std","process_close") static function _close( p : ProcessHandle ) : Void { }

+ 2 - 1
std/java/_std/sys/io/Process.hx

@@ -77,8 +77,9 @@ class Process {
 		return new java.lang.ProcessBuilder(pargs);
 	}
 
-	public function new( cmd : String, ?args : Array<String> ) : Void
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void
 	{
+		if( detached ) throw "Detached process is not supported on this platform";
 		var p = proc = createProcessBuilder(cmd, args).start();
 		stderr = new ProcessInput(p.getErrorStream());
 		stdout = new ProcessInput(p.getInputStream());

+ 4 - 1
std/lua/_std/sys/io/Process.hx

@@ -73,7 +73,10 @@ class Process {
 	}
 
 
-	public function new( cmd : String, ?args : Array<String>){
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool){
+	
+		if( detached ) throw "Detached process is not supported on this platform";
+	
 		var _stdout = new Pipe(false);
 		var _stderr = new Pipe(false);
 		var _stdin  = new Pipe(false);

+ 2 - 1
std/neko/_std/sys/io/Process.hx

@@ -92,7 +92,8 @@ private class Stdout extends haxe.io.Input {
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
 
-	public function new( cmd : String, ?args : Array<String> ) : Void {
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void {
+		if( detached ) throw "Detached process is not supported on this platform";
 		p = try 
 			_run(untyped cmd.__s, neko.Lib.haxeToNeko(args))
 		catch( e : Dynamic )

+ 2 - 1
std/php/_std/sys/io/Process.hx

@@ -85,7 +85,8 @@ class Process {
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
 
-	public function new( cmd : String, ?args : Array<String> ) : Void {
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void {
+		if( detached ) throw "Detached process is not supported on this platform";
 		var pipes = untyped __call__("array");
 		var descriptorspec = untyped __php__("array(
 			array('pipe', 'r'),

+ 2 - 1
std/php7/_std/sys/io/Process.hx

@@ -133,7 +133,8 @@ class Process {
 
 		`close()` should be called when the `Process` is no longer used.
 	*/
-	public function new( cmd : String, ?args : Array<String> ) : Void {
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void {
+		if( detached ) throw "Detached process is not supported on this platform";
 		var descriptors = Syntax.arrayDecl(
 			Syntax.arrayDecl('pipe', 'r'),
 			Syntax.arrayDecl('pipe', 'w'),

+ 2 - 1
std/python/_std/sys/io/Process.hx

@@ -36,7 +36,8 @@ class Process {
 
 	var p:Popen;
 
-	public function new( cmd : String, ?args : Array<String> ) : Void {
+	public function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void {
+		if( detached ) throw "Detached process is not supported on this platform";
 		p = Popen.create(args == null ? cmd : [cmd].concat(args), { shell : args == null, stdin : Subprocess.PIPE, stdout: Subprocess.PIPE, stderr : Subprocess.PIPE });
 		this.stdout = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stdout)));
 		this.stderr = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stderr)));

+ 3 - 1
std/sys/io/Process.hx

@@ -48,9 +48,11 @@ extern class Process {
 		 2. When `args` is not given or is `null`, command arguments can be appended to `cmd`. No automatic quoting/escaping will be performed. `cmd` should be formatted exactly as it would be when typed at the command line.
 		It can run executables, as well as shell commands that are not executables (e.g. on Windows: `dir`, `cd`, `echo` etc).
 
+		`detached` allows the created process to be standalone. You cannot communicate with it but you can look at its exit code.
+		
 		`close()` should be called when the `Process` is no longer used.
 	*/
-	function new( cmd : String, ?args : Array<String> ) : Void;
+	function new( cmd : String, ?args : Array<String>, ?detached : Bool ) : Void;
 
 	/**
 		Return the process ID.