Cygwin: Command works on the console, not in a .bat

1

This command works in the Cygwin console:

me@WDX5CG625Q ~
$ cd "/cygdrive/c/Program Files/apache Software Foundation/Tomcat 8.5"

mw@WDX5CG62Q /cygdrive/c/Program Files/apache Software Foundation/Tomcat 8.5
$

But not in a .bat file:

tom.bat:

cd "/cygdrive/c/Program Files/Apache Software Foundation/Tomcat 8.5"

output:

me@WDX5CG625Q ~
$ ./tom.bat

C:\cygwin64\home\me>cd "/cygdrive/c/Program Files/Apache Software Foundation/Tomcat 8.5"
The system cannot find the path specified.

me@WDX5CG625Q ~
$

Also tried:

  • With a #!/bin/bash
  • Without quotes
  • Without quotes and spaces escaped
  • With quotes and spaces escaped

Always get the “cannot find” message.

Mark Athas

Posted 2018-06-14T16:05:35.757

Reputation: 13

1The working version has "apache" with a small "a"; the failing version has a capital "A". Unix file names are case-sensitive. – AFH – 2018-06-14T16:29:35.710

Answers

1

When you run a .BAT file from Cygwin, it runs as a batch file, using the Windows command interpreter (CMD.EXE, a.k.a. “Command Prompt”).  So

  • If you want to run a batch file, using primarily Windows CLI commands, use the Windows version of the pathname: C:\Program Files\apache Software Foundation\Tomcat 8.5.  It’s probably OK if you use / instead of \, just as it is in an ordinary Windows Command Prompt.  Don’t worry about case.
  • If you want to run a Unix shell script, don’t use the .BAT extension.

G-Man Says 'Reinstate Monica'

Posted 2018-06-14T16:05:35.757

Reputation: 6 509