/* A single handy function to send debuging output to a new xterm. * Copyright (C) 2002 Kasper Dupont * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include #include FILE * debugxterm(const char * name, int keepopen) { FILE * r; char buf[999]; int pipefd[2]; pipe(pipefd); if (!keepopen) fcntl(pipefd[1],F_SETFD,1); sprintf(buf,"xterm -title '%s' -e cat /proc/self/fd/%d &",name,pipefd[0]); system(buf); close(pipefd[0]); r=fdopen(pipefd[1],"w"); setbuf(r,NULL); return r; } int main() { FILE *f=debugxterm("Window title",1); fprintf(f,"Hello World!\n"); sleep(1); return 0; }