|
发表于 2011-3-15 10:41:29
|
显示全部楼层
下面是一段摘自perl open的描述:
If you open a pipe on the command '-' , i.e., either '|-' or '-|' with 2-arguments (or 1-argument) form of open(), then there is an implicit fork done, and the return value of open is the pid of the child within the parent process, and 0 within the child process. (Use defined($pid) to determine whether the open was successful.) The filehandle behaves normally for the parent, but I/O to that filehandle is piped from/to the STDOUT/STDIN of the child process. In the child process, the filehandle isn't opened--I/O happens from/to the new STDOUT/STDIN. Typically this is used like the normal piped open when you want to exercise more control over just how the pipe command gets executed, such as when running setuid and you don't want to have to scan shell commands for metacharacters.
open(DATE,"-|"),这通常应该是3参数形式,然而没有通过第三个参数给open传递要执行的命令,结果就是上面描述的行为。
open()会隐含fork调用,创建原来进程的一个拷贝,这样open有两次返回,在父进程,返回值为子进程pid,在子进程,返回0,并且子进程的标准输出被送到父进程标准输入,父进程的标准输出被送到子进程的标准输入。
如果你使用常规的3参数形式,后面的exec就不会被执行了。 |
|