首先,我会向您展示一些小伪代码:
cpid = forkpty (&compipe, NULL, NULL, NULL);
//yes i have some error handling here, but its not important yet
if (cpid == 0) //child process
{
//here are some pipes closed,
//and the forked child will exec(ute) third party process
}
else //parent process
{
//here are just closing some other pipe ends,
//and settings up some fcntl flags like O_NONBLOCK
if (string (execResult) == "fail")
{
//HERE ARE THE PROBLEM!!
//This debug message will print to the pseudo-terminal (i think)
//because it is not visible in "main"-terminal / console
gui -> appendDbg (Output::EROR, "Could not execute FOO");
printDbg (EROR, "Could not execute FOO");
}
else
{
//But I don't understand why this debug message prints to
//the "main"-terminal where the application was started from
printDbg (INFO, "Starting child process: 'FOO' with PID: " +to_string (cpid));
printChildsOut();
}
}
好的,我的问题在if-else部分中描述,其中将检查exec(ution)结果。
问题是我看不到我的调试消息'EROR ...'',但是我可以在我的“main”-terminal中看到名为'INFO ...'的信息调试消息,其中应用程序是从
顺便说一句,函数'printDbg'是我自己开发的,它只是通过'cout'来打印消息。