2 summary:: pipe stdin to, or stdout from, a unix shell command
3 related:: Classes/UnixFILE
7 Pipe stdin to, or stdout from, a unix shell command. Pipe treats the shell command as if it were a UnixFILE, and returns nil when done. See link::Classes/UnixFILE:: for details of the access methods. Pipe must be explicitly closed. Do not rely on the garbage collector to do this for you!
14 A link::Classes/String:: representing a valid shell command.
17 A link::Classes/String:: representing the mode. Valid modes are "w" (pipe to stdin) and "r" (pipe from stdout).
21 private::prClose, prOpen
27 A command line link::Classes/String:: passed to popen.
30 A link::Classes/String:: passed to popen, so should be one of: "r","w"
33 Closes the pipe, waiting for the command to finish. You must do this explicitly before the Pipe object is garbage collected.
35 returns:: The exit status of the command (an Integer).
40 For anyone still using OS X 10.3, unix commands like pipe do not work when the server is booted; quit the server, otherwise sc crashes. More recent OS X is not affected.
44 // this pipes in stdout from ls
47 p = Pipe.new("ls -l", "r"); // list directory contents in long format
48 l = p.getLine; // get the first line
49 while({l.notNil}, {l.postln; l = p.getLine; }); // post until l = nil
50 p.close; // close the pipe to avoid that nasty buildup
54 A more time-intensive request:
58 p = Pipe.new("ping -c10 sourceforge.net", "r"); // list directory contents in long format
59 l = p.getLine; // get the first line
60 while({l.notNil}, {l.postln; l = p.getLine; }); // post until l = nil
61 p.close; // close the pipe to avoid that nasty buildup