[FreeNX-kNX] [PATCH 1/5] Redirect child stdout to parent process

Otavio Salvador otavio at ossystems.com.br
Fri Nov 7 17:10:23 UTC 2008


From: Luis Gustavo S. Barreto <gustavo at ossystems.com.br>

Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
---
 nxcl/test/nxcmd.cpp |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/nxcl/test/nxcmd.cpp b/nxcl/test/nxcmd.cpp
index 98d603b..228e4b8 100644
--- a/nxcl/test/nxcmd.cpp
+++ b/nxcl/test/nxcmd.cpp
@@ -161,6 +161,12 @@ main (int argc, char **argv)
 	stringstream arg;
 	arg << i;		
 
+	int fd[2];
+	if (pipe(fd) == -1) {
+		cerr << "pipe() failed" << endl;
+		exit(-1);
+	}
+
 	/* fork and exec the nxcl */
 	pid = fork();
 	switch (pid) {
@@ -168,6 +174,9 @@ main (int argc, char **argv)
 		cerr << "Can't fork()!" << endl;
 		exit (-1);
 	case 0:
+		close(fd[1]);
+		close(fd[0]);
+
 		// This is the CHILD process
 		// Allocate memory for the program arguments
 		// 1+ to allow space for NULL terminating pointer
@@ -180,6 +189,9 @@ main (int argc, char **argv)
 		exit(-1);
 
 	default:
+		close(fd[1]);
+		close(fd[0]);
+
 		// This is the PARENT process
 		cout << "NXCMD> forked the nxcl process; continuing.\n";
 		break;
-- 
1.6.0.3.640.g6331a




More information about the FreeNX-kNX mailing list