简体   繁体   English

将消息从子进程发送到父进程

[英]Send messages from child process to parent

I am executing the parent code. 我正在执行父代码。 I then do a fork and then execvpe. 然后,我先执行fork,然后执行execvpe。 The new program that i "execvpe" throws a lot of console messages and i want to hide those. 我“ execvpe”的新程序会抛出很多控制台消息,我想隐藏这些消息。

Is it possible for me to redirect all my stdout and stderr messages in the child process onto a file? 我是否可以将子进程中的所有stdout和stderr消息重定向到文件上?

I tried a close(1) so that i dont dump messages on console (stdout) and that didnt help 我尝试了close(1),这样我就不会在控制台(stdout)上转储消息了,这没有帮助

pid_t pid = fork();
/* Child process */
if (pid == 0) {
    /* Open log file */
    int log = creat("logfile", 0644);
    /* Redirect stdout to log file */
    close(1);
    dup(log);
    /* Redirect stderr to log file */
    close(2);
    dup(log);
    /* Execute other program: its stdout & stderr (1 & 2) will both point to logfile */
    execvpe(.......);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM