Lines Matching +full:write +full:- +full:to +full:- +full:read
1 .\" Copyright (C) Caldera International Inc. 2001-2002. All rights reserved.
20 .\" nor the names of other contributors may be used to endorse or promote
26 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 It is often easier to use a program written
42 by someone else than to invent one's own.
43 This section describes how to
48 The easiest way to execute a program from another
49 is to use
57 For instance, to time-stamp the output of a program,
65 If the command string has to be built from pieces,
66 the in-memory formatting capabilities of
83 Low-Level Process Creation \(em Execl and Execv
88 you will have to construct calls to other programs
94 The most basic operation is to execute another program
105 The first argument to
110 of the command; you have to know where it is found
115 but this is seldom used except as a place-holder.
131 return to the original program.
136 Here it is natural to make the second pass
141 The one exception to the rule that the original program never gets control
157 is useful when you don't know in advance how many arguments there are going to be.
164 is an array of pointers to the arguments;
176 (This arrangement is identical to the
182 you have to know precisely where the command is located.
201 execl("/bin/sh", "sh", "-c", commandline, NULL);
203 The shell is assumed to be at a fixed place,
206 .UL -c
207 says to treat the next argument
216 Now we will show how to regain control after running
225 overlaying program to finish.
231 splits the program into two copies, both of which continue to run.
241 is non-zero; it is the process number of the child.
242 Thus the basic way to call, and return from,
246 execl("/bin/sh", "sh", "-c", cmd, NULL); /* in child */
261 returns non-zero
267 .UL -1 ).
269 More often, the parent wants to wait for the child to terminate
291 of the terminated child, if you want to check it against the value
308 encodes in its low-order eight bits
310 it is 0 for normal termination and non-zero to indicate
313 of the call to
317 for all programs to return meaningful
341 that has been read by the caller.
364 for a process to set up its own plumbing;
378 if (stat == -1)
384 is the read side of the pipe and
388 .UL read ,
389 .UL write
398 If the write side of the pipe is closed,
400 .UL read
404 let us write a function called
412 read or write that process, according to
417 fout = popen("pr", WRITE);
424 .UL write
427 will send their data to that process
438 The child decides whether it is supposed to read or write,
444 These closes are necessary to make end-of-file tests work properly.
445 For example, if a child that intends to read
446 fails to close the write end of the pipe, it will never
452 #define READ 0
453 #define WRITE 1
454 #define tst(a, b) (mode == READ ? (b) : (a))
466 close(tst(p[WRITE], p[READ]));
468 dup(tst(p[READ], p[WRITE]));
469 close(tst(p[READ], p[WRITE]));
470 execl("/bin/sh", "sh", "-c", cmd, 0);
473 if (popen_pid == -1)
475 close(tst(p[READ], p[WRITE]));
476 return(tst(p[WRITE], p[READ]));
484 that the task is to create a child process that will read data from the parent.
487 closes the write side of the pipe,
488 leaving the read side open.
492 dup(tst(p[READ], p[WRITE]));
494 are the conventional way to associate the pipe descriptor
508 is to copy the file descriptor for the pipe (read side)
510 thus the read side of the pipe becomes the standard input.
512 Finally, the old read side of the pipe is closed.
515 when the child process is supposed to write
517 You may find it a useful exercise to step through that case.
526 is that it is desirable to wait for the termination of the child process.
531 is that only a bounded number of unwaited-for children
535 lays the child to rest.
551 while ((r = wait(&status)) != popen_pid && r != -1);
552 if (r == -1)
553 status = -1;
560 The calls to