Process.hx 1.1 KB

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