Question about Cygwin process behaviour and bash interactive mode

Igor Pechtchanski pechtcha@cs.nyu.edu
Sat Sep 14 11:04:00 GMT 2002


On Sat, 14 Sep 2002, Chris January wrote:

> If I launch a Windows command shell (cmd.exe) from, e.g. a Window shortcut,
> and then run bash from that shell, bash starts interactive mode.
> If I launch a Cygwin bash shell from, e.g. cygwin.bat, then run cmd from
> that shell (I type cmd), a Windows command shell starts. If I then run bash
> from that command shell, bash starts in non-interactive mode.
>
> Can anyone explain this behaviour and why bash starts in interactive mode in
> one case, and non-interactive mode in the other, even though both times it
> is launched from cmd.exe?

Chris,

My guess is that isatty() behaves differently depending on whether we have
a first-level or a second-level invocation of cmd.exe...

Quoting from the bash-2.05b-3 source (shell.c:462):

  /* First, let the outside world know about our interactive status.
     A shell is interactive if the `-i' flag was given, or if all of
     the following conditions are met:
        no -c command
        no arguments remaining or the -s flag given
        standard input is a terminal
        standard output is a terminal
     Refer to Posix.2, the description of the `sh' utility. */

  if (forced_interactive ||             /* -i flag */
      (!local_pending_command &&        /* No -c command and ... */
       wordexp_only == 0 &&             /* No --wordexp and ... */
       ((arg_index == argc) ||          /*   no remaining args or... */
        read_from_stdin) &&             /*   -s flag with args, and */
       isatty (fileno (stdin)) &&       /* Input is a terminal and */
       isatty (fileno (stdout))))       /* output is a terminal. */
    init_interactive ();
  else
    init_noninteractive ();

The Posix.2 standard can be found here:
http://www.educat.hu-berlin.de/doc/Posix-1003.2.txt

Quoting from isatty source (newlib/libc/posix/isatty.c:12):

  if (fstat (fd, &buf) < 0)
    return 0;
  if (S_ISCHR (buf.st_mode))
    return 1;
  return 0;

So, isatty() simply checks if the file descriptor given is a character
device or not.  I'm not sure quite how this works with windows programs
started from bash.

Hope this helps.
	Igor

P.S.
> chris@AVACADO ~
I'm just curious, is "avocado" in your hostname misspelled on purpose? ;-)

-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95.  Something is wrong here. -- SC sig file


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list