Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

problem invoking windows' netsh in cygwin's bash shell

I have 3 computers (let me call them N1, N2, N3) with the following systems:

  • N1: Windows 2019 Server Essential 64 bit, with CYGWIN_NT-10.0 -3.0.7(0.338/5/3) x86_64
  • N2: Windows 10 professional 64 bit, with CYGWIN_NT-10.0 - 3.1.7(0.340/5/3) x86_64
  • N3: Windows 10 professional 64 bit, with CYGWIN_NT-10.0 - 3.1.7(0.340/5/3) x86_64

Accessing them through Cygwin's SSHD from a Linux machine, I can (remotely) run on all of these 3 computers (windows-)commands like

  • /c/Windows/System32/NET start <SERVICENAME>
  • /c/Windows/System32/ATTRIB
  • /c/Windows/System32/HELP
  • /c/Windows/System32/NETSH
  • ...

and they all work as expected.

Except the command NETSH on N3!

On N3, invoking

/c/Windows/System32/NETSH

does nothing at all: no error message, no command prompt, even when providing arguments like "?" (with or without quotes) or any other args, when using fully qualified command-path or command-NAME only, just nothing happens, which looks like this:

  user@machine ~ # /c/Windows/System32/NETSH
  user@machine ~ #      

(NB: on the problem machine, N3, also with a Cygwin version a little bit older than the newest (actual) one, CYGWIN_NT-10.0 - 3.1.4(0.340/5/3) x86_64, the results were the same)

Is there anyone having an idea?? Thank you!!

Schogol

question from:https://stackoverflow.com/questions/65908939/problem-invoking-windows-netsh-in-cygwins-bash-shell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is the interaction between the Mintty and the need of netsh to be interactive and been not a Cygwin program. See for details:

https://github.com/mintty/mintty/wiki/Tips#inputoutput-interaction-with-alien-programs

If you run netsh under Cygwin using the Cygwin.bat present on you root, you have no issue as the terminal is the same of CMD

$ netsh
netsh>interface
In zukünftigen Versionen von Windows wird die Netsh-Funktionalit?t
für TCP/IP von Microsoft entfernt.
..
Unter https://go.microsoft.com/fwlink/?LinkId=217627 finden Sie
weitere Informationen zu PowerShell-Befehlen für TCP/IP.
netsh interface>
netsh interface>quit

A workaround under Mintty is to use winpty as intermediate
https://github.com/rprichard/winpty/releases

Assuming you are using a 64bit system:

$ wget https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-cygwin-2.8.0-x64.tar.gz
$ tar -xf winpty-0.4.3-cygwin-2.8.0-x64.tar.gz
$ cp -r  winpty-0.4.3-cygwin-2.8.0-x64/* /usr/local
$ winpty netsh
netsh>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...