I tried using dup and dup2 to make a backup of the thread's STDOUT and
then attach it to the socket returned from accept(). I don't seem to
get any errors but the printf output still goes to the serial console
instead of the socket. The application runs fine and the user is able
to interact with the shell. Unfortunately the printf output is still
only going to the serial console.
I am using vxWorks-6.4. Has anyone else tried redirecting stdout to a
socket? What worked for you?
Thanks for your time and help,
-Brian
BTW: Below is an example of what I am trying.
/
*--------------------------------------------------------------------------
*/
/**
@brief Redirects stdout to the socket and starts the socket shell for
the connection
@param connectSocket Socket returned by accept()
*/
void
socket_cdk_shell(int connectSocket)
{
int oldStdOut = 0; /* original source of STD_OUT */
/* save the original source of STD_OUT */
oldStdOut = dup(STD_OUT);
if (ERROR == oldStdOut) {
printf("ERROR: Failed to duplicate STD_OUT\n");
}
else {
/* redirect the socket to STD_IN */
if (ERROR == dup2(connectSocket, STD_OUT)) {
printf("ERROR: Failed to redirect the connection socket to STD_OUT
\n");
}
else {
/* Launch the shell - returns when user exits */
socket_shell(connectSocket);
/* I know for certain that I get to here */
/* reattach STD_OUT */
if (ERROR == dup2(oldStdOut, STD_OUT)) {
printf("ERROR: Failed to reattach STD_OUT\n");
}
else {
close(oldStdOut);
}
}
}
return void;
}
Is this to execute in the kernel or in the RTP environment?
--
PAD
For the kernel environment try using ioTaskStdSet().
Cheers,
--
PAD