Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 13th, 2012  |  syntax: None  |  size: 1.03 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. const GLib = imports.gi.GLib;
  2. const Gio = imports.gi.Gio;
  3.  
  4. let [res, out, err, status] = GLib.spawn_command_line_sync('ls -la');
  5. print(out);
  6.  
  7. let [res, out] = GLib.spawn_command_line_sync('ls -la');
  8. print(out);
  9.  
  10. let [res, out] = GLib.spawn_sync(null, ['/bin/ls', '-la'], null, 0, null);
  11. print(out);
  12.  
  13. let [res, out] = GLib.spawn_sync(GLib.getenv('HOME'), ['/bin/ls', '-la'], null, 0, null);
  14. print(out);
  15.  
  16. let [res, out] = GLib.spawn_sync(null, ['ls', '-la'], null, GLib.SpawnFlags.SEARCH_PATH, null);
  17. print(out);
  18.  
  19. GLib.spawn_command_line_async('ls -la');
  20.  
  21. let [res, pid, in_fd, out_fd, err_fd]  = GLib.spawn_async_with_pipes(null, ['/bin/cat'], null, 0, null);
  22. let out_reader = new Gio.DataInputStream({
  23.   base_stream: new Gio.UnixInputStream({fd: out_fd})
  24. });
  25. let in_writer = new Gio.DataOutputStream({
  26.   base_stream: new Gio.UnixOutputStream({fd: in_fd})
  27. });
  28. let data = ["hoge", "fuga", ""].join("\n");
  29. in_writer.put_string(data, null);
  30. let [out, size] = out_reader.read_line(null);
  31. print(out);
  32. let [out, size] = out_reader.read_line(null);
  33. print(out);