From owner-freebsd-questions@FreeBSD.ORG Wed Jul 23 17:34:22 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A2E3737B401 for ; Wed, 23 Jul 2003 17:34:22 -0700 (PDT) Received: from smtp806.mail.sc5.yahoo.com (smtp806.mail.sc5.yahoo.com [66.163.168.185]) by mx1.FreeBSD.org (Postfix) with SMTP id 3A5B643F85 for ; Wed, 23 Jul 2003 17:34:22 -0700 (PDT) (envelope-from andrevv@users.sourceforge.net) Received: from adsl-64-165-225-5.dsl.lsan03.pacbell.net (HELO 192.168.1.100) (dskxe@pacbell.net@64.165.225.5 with plain) by smtp-sbc-v1.mail.vip.sc5.yahoo.com with SMTP; 24 Jul 2003 00:34:20 -0000 From: Andrew Barton To: freebsd-questions@freebsd.org Content-Type: text/plain Organization: Message-Id: <1058981617.2733.6.camel@localhost> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2-3mdk Date: 23 Jul 2003 17:33:37 +0000 Content-Transfer-Encoding: 7bit Subject: forkpty and fdopen X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jul 2003 00:34:22 -0000 I'm trying to make a program that uses forkpty(), then runs sh in the child process, and then writes to the child using streams. But it doesn't work! It hangs on the wait() call; apparently the child never sees the "exit\n". #include #include #include main() { int fd; pid_t pid; pid = forkpty (&fd, 0, 0, 0); if (pid == 0) { execlp ("sh", "sh", (void *)0); _exit (1); } else if (pid == -1) { exit (1); } else { FILE *F; F = fdopen (fd, "w"); fprintf (F, "exit\n"); fflush (F); wait (0); } exit (0); }