Hi Patrick, On Mon 16.09.2013 21:58:15, Patrick Serru wrote: > Le lundi 16 septembre 2013, vous avez écrit : > > On Mon, Sep 16, 2013 at 06:52:16AM -0500, Patrick Serru <[email protected]> > > wrote: > > > > Have you looked at the -pty-fd option? That will both do away with the > > need to -e something, and it should work with urxvtc, too (but also urxvt > > of course). > > Thank you for your response. I searched and searched. I found only two > references in the two pages given by Google. All but one is the content > of …/share/man/man7/urxvt.7, and the single other one was "Run a program > under a pty session". What I understoud is that there are a lot of > missunderstanding possible. > > Let me rephrase the question: I would like to know how to write in C a piece > of code that: > would open a graphical (separate) window running urxvt and then > would open some bidirectional pipe to be able to > - write to the standard input of that just opened urxvt running graphical > window and > - read from the standard output of that urxvt window.
That is exactly what the -pty-fd option is supposed to do. The bidirectional pipe is in this case this file descriptor. The manpage has a nice example in perl that illustrates how to use urxvt for pushing and reading arbitrary stuff to a terminal window, it is only missing the part where it thats another binary and connects it to this terminal. As I needed a small challenge today I tried to grab some pieces of code and implement this in C. I really have to admit: despite I disliked perl for many years in cases like this one I really love it. 8 lines of perl versus 44 lines of C are pretty nice. I attached the small program, you need to compile it using "gcc -lutil urxvt-pty-test.c". Hopefully it won't burn your house, as this is my probably third program that actually compiles and runs. If anyone want's to critise it: please do. Regards, Andre -- Andre Klärner
// pty-example.c // Author: Allen Porter <[email protected]> // tinkered with by Andre Klärner <[email protected]> // in order to demonstrate using urxvt's -pty-fd #include <stdio.h> #include <errno.h> #include <pty.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> int main(int argc, char* argv[]) { int fd; pid_t pid = forkpty(&fd, NULL, NULL, NULL); if (pid == -1) { perror("forkpty"); return 1; } else if (pid == 0) { if (execlp("/usr/bin/watch", "watch", "ps f", NULL) == -1) { perror("execlp"); } fprintf(stderr, "program exited.\n"); return 1; } printf("Child process: %d\n", pid); printf("master fd: %d\n", fd); // Set non-blocking int flags; if ((flags = fcntl(fd, F_GETFL, 0)) == -1) flags = 0; if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { perror("fcntl"); return 1; } char strfd[12]; sprintf( strfd, "%i", fd); if (execlp("/usr/bin/urxvt", "urxvt","-pty-fd", strfd, (char *)0 ) == -1) { perror("execlp"); } fprintf(stderr, "program exited.\n"); return 0; }
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ rxvt-unicode mailing list [email protected] http://lists.schmorp.de/cgi-bin/mailman/listinfo/rxvt-unicode
