polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Files / Pipe.html
blob502dc8b852871cd95fd2a9dfd3eae5eb2e50a0c6
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.41">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #962617}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
16 span.s1 {color: #0024f8}
17 span.s2 {text-decoration: underline}
18 span.s3 {color: #0027b1}
19 span.s4 {color: #000000}
20 span.s5 {color: #606060}
21 span.s6 {color: #962617}
22 span.Apple-tab-span {white-space:pre}
23 </style>
24 </head>
25 <body>
26 <p class="p1"><b>Pipe</b></p>
27 <p class="p2"><br></p>
28 <p class="p3"><b>superclass: UnixFILE</b></p>
29 <p class="p2"><br></p>
30 <p class="p3">Pipe stdin to, or stdout from, a unix shell command. Pipe treats the shell command as if it were a <b>UnixFILE</b>, and returns nil when done. See <a href="UnixFILE.html"><span class="s1"><b>UnixFILE</b></span></a><b> </b>for details of the access methods. Pipe must be explicitly closed. Do not rely on the garbage collector to do this for you!</p>
31 <p class="p2"><br></p>
32 <p class="p2"><br></p>
33 <p class="p3"><b>Note: </b>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.<span class="Apple-converted-space"> </span></p>
34 <p class="p2"><br></p>
35 <p class="p2"><br></p>
36 <p class="p3"><b>*new(commandLine, mode)</b></p>
37 <p class="p2"><br></p>
38 <p class="p3"><b><span class="Apple-tab-span"> </span>commandLine</b> - A String representing a valid shell command.</p>
39 <p class="p3"><span class="Apple-tab-span"> </span><b>mode </b>- A string representing the mode. Valid modes are "w" (pipe to stdin) and "r" (pipe from stdout).</p>
40 <p class="p2"><span class="Apple-tab-span"> </span></p>
41 <p class="p3"><b>close</b></p>
42 <p class="p3"><b><span class="Apple-tab-span"> </span></b>Closes the pipe. You must do this explicitly before the Pipe object is garbage collected.</p>
43 <p class="p2"><span class="Apple-tab-span"> </span></p>
44 <p class="p3"><b><span class="s2">Examples</span></b></p>
45 <p class="p2"><span class="Apple-tab-span"> </span></p>
46 <p class="p4">// quit the server</p>
47 <p class="p5">s.quit;</p>
48 <p class="p6"><br></p>
49 <p class="p4">// this pipes in stdout from ls</p>
50 <p class="p5">(</p>
51 <p class="p5"><span class="s3">var</span> p, l;</p>
52 <p class="p4"><span class="s4">p = </span><span class="s3">Pipe</span><span class="s4">.new(</span><span class="s5">"ls -l"</span><span class="s4">, </span><span class="s5">"r"</span><span class="s4">);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// list directory contents in long format</p>
53 <p class="p5">l = p.getLine;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">// get the first line</span></p>
54 <p class="p5">while({l.notNil}, {l.postln; l = p.getLine; });<span class="Apple-tab-span"> </span><span class="s6">// post until l = nil</span></p>
55 <p class="p4"><span class="s4">p.close;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// close the pipe to avoid that nasty buildup</p>
56 <p class="p5">)</p>
57 <p class="p6"><br></p>
58 <p class="p6"><br></p>
59 <p class="p5">A more time-intensive request:</p>
60 <p class="p5">(</p>
61 <p class="p5"><span class="s3">var</span> p, l;</p>
62 <p class="p4"><span class="s4">p = </span><span class="s3">Pipe</span><span class="s4">.new(</span><span class="s5">"ping -c10 sourceforge.net"</span><span class="s4">, </span><span class="s5">"r"</span><span class="s4">);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// list directory contents in long format</p>
63 <p class="p5">l = p.getLine;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">// get the first line</span></p>
64 <p class="p5">while({l.notNil}, {l.postln; l = p.getLine; });<span class="Apple-tab-span"> </span><span class="s6">// post until l = nil</span></p>
65 <p class="p4"><span class="s4">p.close;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// close the pipe to avoid that nasty buildup</p>
66 <p class="p5">)</p>
67 <p class="p6"><br></p>
68 <p class="p6"><br></p>
69 </body>
70 </html>