exec reopen

Hi,

I am trying to redirect th console during my c program execution using:

     swawnlp(P_WAIT,"reopen","reopen","/dev/myNewConsole");

/dev/myNewConsole exists and I can sucessfully do:

     reopen /dev/myNewConsole from the commandline.

any ideas :question:

first, reopen isn’t a shell utility, it is a shell built-in and so you can’t use it like you are trying to use it. Secondly, it reopen’s the current shell’s FD’s and not the parent processes.

You want to look into using dup2(). Something like this:

int newout;
newout = open( “/dev/MyConsole”, O_RDONLY );
dup2( newout, fileno( stdout ) );

For each input/output/error stream you want to change.

Thanks CDM.

I tried:

newout = open( "/dev/MyConsole", O_RDWR ); 
dup2( newout, fileno( stdout )); 
dup2( newout, fileno( stdin )); 
dup2( newout, fileno( stderr )); 

but no luck.

the open and dups return no errors but the console does not change.

http://qnx.wox.org/qnx/sources/conout.c

qcc -o conout conout.c
./conout /dev/con1

I have test it on my consoles, on my serial ports and even over
qnet to a tty session running on my iPaq! Works just great.

Hope this helps you out.