View topic - exec reopen

exec reopen

anything that doesn't fit to other groups.

exec reopen

Postby ddread » Sat Nov 16, 2002 2:06 am

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 :?:
ddread
New Member
 
Posts: 3
Joined: Sat Nov 16, 2002 2:00 am

That isn't how to do it.

Postby cdm » Sat Nov 16, 2002 9:59 am

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.
cdm
QNX Master
 
Posts: 789
Joined: Fri Jul 05, 2002 9:38 am

Postby ddread » Mon Nov 18, 2002 10:32 pm

Thanks CDM.

I tried:

Code: Select all
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.
ddread
New Member
 
Posts: 3
Joined: Sat Nov 16, 2002 2:00 am

Sample Code

Postby cdm » Wed Nov 20, 2002 4:56 am

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.
cdm
QNX Master
 
Posts: 789
Joined: Fri Jul 05, 2002 9:38 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests