Process.hx 822 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package sys.io;
  2. import python.lib.Subprocess;
  3. import python.lib.subprocess.Popen;
  4. class Process {
  5. public var stdout(default,null) : haxe.io.Input;
  6. public var stderr(default,null) : haxe.io.Input;
  7. public var stdin(default,null) : haxe.io.Output;
  8. var p:Popen;
  9. public function new( cmd : String, args : Array<String> ) : Void {
  10. p = Popen.create([cmd].concat(args), { stdin : Subprocess.PIPE, stdout: Subprocess.PIPE, stderr : Subprocess.PIPE });
  11. this.stdout = new FileInput (cast p.stdout);
  12. this.stderr = new FileInput (cast p.stderr);
  13. this.stdin = new FileOutput(cast p.stdin);
  14. }
  15. public function getPid() : Int {
  16. return p.pid;
  17. }
  18. public function exitCode() : Int {
  19. return p.returncode;
  20. }
  21. public function close() : Void {
  22. p.terminate();
  23. }
  24. public function kill() : Void {
  25. p.kill();
  26. }
  27. }