[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ncurses on pipes

From: Robert Lemmen
Subject: ncurses on pipes
Date: Wed, 13 Jun 2007 14:47:53 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

hi folks,

i have searched the web and the archive and it looks like this problems
pops up every now and then, but without any real answer. i want to write
a network server that allows clients to connect via telnet and be
confronted with a curses user interface. sounds simple. but in order to
do so, i need to create a curses screen that is not connected to a tty
but to a socket or even better a pipe (since i want to do the telnet
protocol handling between the socket and the pipe). the following ugly
snippet illustrates the problem:

#include <curses.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#define PIPE_IN         1
#define PIPE_OUT        0

int main(int argc, char *argv[]) {
        int opipe[2];
        if (pipe(opipe) == -1) {
                fprintf(stderr, "could not create pipe: %s\n", strerror(errno));
                return 1;
        SCREEN *screen;
        screen = newterm("xterm", stdout/*fdopen(opipe[PIPE_IN], "w")*/, stdin);
        move(3, 3);

        int len;
        char data;
        int opts = fcntl(opipe[PIPE_OUT], F_GETFL) | O_NONBLOCK;
        fcntl(opipe[PIPE_OUT], F_SETFL, opts);
        while ((len = read(opipe[PIPE_OUT], &data, sizeof(data))) > 0) {
                fprintf(stderr, "%02X ", data);
                /* or
                write(stdout, data, sizeof(data));*/
        return 0;

if i run newterm with stdout everything works as expected, if i use the
pipe and then copy everything from the pipe to stdout, it doesn't.
interestingly it does the refresh(), but addstr() does not generate any
data in the pipe. 

is there a way to get this stuff working? am i using a completely wrong
approach? any hints?

thanks  robert

Robert Lemmen                               http://www.semistable.com 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]