Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Redirecting STDOUT to Socket

508 views
Skip to first unread message

Brian @ VPS

unread,
May 20, 2009, 3:12:19 PM5/20/09
to
I have a text based socket application (similar to telnet) which can
cause code to run that uses printf to output information that is for
the user. Unfortunately the user is not looking at the serial console
because they connected using telnet. I would like to redirect STDOUT
to the socket.

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;
}

PAD

unread,
May 21, 2009, 4:47:00 PM5/21/09
to
Hello,

Is this to execute in the kernel or in the RTP environment?

--
PAD

Brian @ VPS

unread,
May 22, 2009, 9:37:39 AM5/22/09
to
I am using kernel tasks but could use RTP's if that helps.

PAD

unread,
May 22, 2009, 3:16:28 PM5/22/09
to
Well, it just is that dup() and dup2() are not supported in the kernel
environment... These routines are support routines for the dup() and
dup2() routines in the RTP environment.

For the kernel environment try using ioTaskStdSet().

Cheers,

--
PAD

0 new messages