25

I'm trying cygwin with emacs. My environment is Windows 7 x64, emacs-24.0.93.1, cygwin 2.769, system encoding is gbk, cygwin's coding system is default to utf-8, and emacs's coding system is default to gbk

I use setup-cygwin to setup cygwin with emacs. And I can launch emacs shell using cygwin bash.But I encountered two problem. First, two warnings at the beginning of bash

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

Second, after bash response, some strange characters appeared. enter image description here

Does anyone know what happened?

7 Answers 7

11

A "known problem," with no known solution (yet):

https://www.emacswiki.org/emacs/NTEmacsWithCygwin#toc2

https://sourceware.org/ml/cygwin/2012-03/msg00347.html

2
  • I can confirm this problem exists with Emacs 23.2.1 as well, not just 23.4.1. The real workaround is not to upgrade Cygwin and instead stick with an older version. Which begs the question: Why is this issue labeled "NTEmacs breaks cygwin bash"? (i.e. should be "cygwin bash breaks NTEmacs").
    – Withheld
    Commented Dec 21, 2012 at 19:56
  • The problem still exists with Cygwin 2.8.1 and Emacs 24.5.1. The Gmane link in the answer does not work. I think this is the mailing list message: sourceware.org/ml/cygwin/2012-03/msg00347.html.
    – mzjn
    Commented Jul 14, 2017 at 16:26
1

Add this to your init:

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

As for your other message, I've started getting that myself only recently. I've run emacs/cygwin/bash for a while, and I'm not sure yet what caused it.

3
  • 1
    Hey, man, it does not works for me... Anyway, thanks for your hint
    – jiluo
    Commented Mar 12, 2012 at 16:24
  • @MartinLuo, just to be sure, you need to restart emacs of course.
    – harpo
    Commented Mar 12, 2012 at 16:27
  • Yes, i restart it indeed, but it remains the same way
    – jiluo
    Commented Mar 12, 2012 at 16:42
1

If nothing else works, you can customise your shell prompt for the case when you are running M-x shell by making use of the following functionality:

M-: (info "(emacs) Interactive Shell") RET

Emacs sends the new shell the contents of the file ~/.emacs_SHELLNAME' as input, if it exists, where SHELLNAME is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is~/.emacs_bash'. If this file is not found, Emacs tries with `~/.emacs.d/init_SHELLNAME.sh'.

So you can specify a prompt without colour codes in that file (i.e. set the PS1 environment variable).

0

Regarding the strange characters, I realised that I had this piece of code messing around:

     ; Always prefer UTF-8 encoding
     ;(prefer-coding-system 'utf-8-with-signature-dos)

And this was causing most commands to fail, because it was adding the BOM () to the command invokation:

     ----------------------------------------------------------
     -*- mode: grep; default-directory: "~/" -*-
     Grep started at Sat Oct 06 02:53:32
     grep -nH -e test
     'grep' is not recognized as an internal or external command,
     operable program or batch file.
0
+50

start a new terminal (bash) with strace -o bash.log bash could help debugging this problem. What it looks like is that some device that bash tries to open is missing appropriate permissions or doesn't even exist.

grep your bash.log file for any /dev strings and check if there is any issues there. For example my bash opens up /dev/tty:

$ grep "/dev" bash.log
open("/dev/tty", O_RDWR|O_NONBLOCK)     = 3
2
  • 2
    No idea if your suggestion will help me solve the problem but since you are the only one answering this question after I opened a bounty, you get it. :) I will report back as soon as I have a chance to implement your solution.
    – uTubeFan
    Commented Dec 5, 2012 at 0:39
  • I don't know whether this answer could help me. But I will try it later when I use Windows, I use Mac most of the time. :) Thanks for your answer!
    – jiluo
    Commented Dec 5, 2012 at 11:28
0

What you're seeing is Emacs choking on some control codes in your PS1 variable. That's why you consistently see that junk just before your prompt gets printed.

Workaround:

Add this to your .bashrc to give yourself a dumbed down prompt when you're running a shell from within Emacs:

if [ "$EMACS" == "t" ]; then
    PS1='\u \w>'
fi

This solution is based on: http://cygwin.com/ml/cygwin/2006-06/msg00491.html

I'm just using a much simpler PS1.

0

Just encountered and solved this problem by installing 64-bit cygwin for my 64-bit Win7 (previously had 32-bit). Pick the right Cygwin setup according to your Windows version.

How to tell your Windows version: "Start" > right-click "Computer" [right side of Start pane] > "Properties" [context menu], look for "System type" about halfway down the window.

During the cygwin setup process, make sure to choose the emacs packages - I picked "regular" emacs, emacs-x11, and emacs-w32 (native compiled for windows). The emacs-w32 looks/feels just like the regular Windows emacs binary as far as I can tell.

A few notes:

  • 64-bit cygwin install in c:\cygwin64 by default (may need to update PATH)
  • Paths in emacs-w32 are specified using unix style pathnames ("/bin/bash")
  • By default emacs-w32 seems to use sh as the shell - you can change that in .emacs by setting explicit-shell-file-name: (setq explicit-shell-file-name "/bin/bash")
  • If you see funny control character (eg ^G and such) you probably want to change your PS1 in .bash_profile
  • You may need to explicitly create your home dir before you can change ~/.bash_profile: mkdir /home/<username>

Hope this helps.

Not the answer you're looking for? Browse other questions tagged or ask your own question.