--- util-linux-2.11z/misc-utils/script.1 2002-01-12 11:45:00.000000000 -0800 +++ ./misc-utils/script.1 2003-05-12 16:40:34.000000000 -0700 @@ -40,6 +40,7 @@ .Sh SYNOPSIS .Nm script .Op Fl a +.Op Fl c Ar COMMAND .Op Fl f .Op Fl q .Op Fl t @@ -69,6 +70,10 @@ or .Pa typescript , retaining the prior contents. +.It Fl c Ar COMMAND +Run the COMMAND rather than an interactive shell. +This makes it easy for a script to capture the output of a program that +behaves differently when its stdout is not a tty. .It Fl f Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can --- util-linux-2.11z/misc-utils/script.c 2002-11-26 08:18:00.000000000 -0800 +++ ./misc-utils/script.c 2003-05-12 16:33:27.000000000 -0700 @@ -91,6 +91,7 @@ char line[] = "/dev/ptyXX"; #endif int aflg = 0; +char *cflg; int fflg = 0; int qflg = 0; int tflg = 0; @@ -135,11 +136,14 @@ } } - while ((ch = getopt(argc, argv, "afqt")) != -1) + while ((ch = getopt(argc, argv, "ac:fqt")) != -1) switch((char)ch) { case 'a': aflg++; break; + case 'c': + cflg = optarg; + break; case 'f': fflg++; break; @@ -284,6 +288,7 @@ void doshell() { + char *opt = cflg? "-c" : "-i"; /*** int t; @@ -301,9 +306,9 @@ (void) dup2(slave, 2); (void) close(slave); #ifdef __linux__ - execl(shell, strrchr(shell, '/') + 1, "-i", 0); + execl(shell, strrchr(shell, '/') + 1, opt, cflg, 0); #else - execl(shell, "sh", "-i", 0); + execl(shell, "sh", opt, cflg, 0); #endif perror(shell); fail();