Running cmd.exe from within Cygwin

16,637

Solution 1

/? is treated as a pattern by bash, where the question mark will fit a single character, so if you have any one-letter files or directories in your Cygwin root, the pattern will be replaced with those. echo /? will show you if that's what's happening. You can escape the question mark with a backslash: /\?. Or quote the whole argument: '/?'.

cygstart c:/windows/system32/cmd will start cmd.exe in its own window.

Solution 2

You can run a batch file from a Cygwin shell directly, you don't even need the intermediate call to cmd. If the batch file requires arguments, they need to be quoted in the Windows fashion; it might be simpler to run cmd /c 'foo.bat "quoted arguments"'.

You don't say in what terminal you're running the shell. Batch files by themselves don't care about that, but the commands that are executed from the batch files might. Cygwin terminal emulators do not emulate Windows consoles, so they are good for Cygwin programs and for stdio-only programs but not for Windows console programs.

If normally run Cygwin shells in a Cygwin terminal (such as rxvt or mintty), You can run the trouble batch files in a separate Windows console with start foo.bat. You might want to run Console2 as a better replacement for the Windows console, and run Windows console applications in Console2 and Cygwin applications in a Cygwin terminal (or even in Console2).

cmd /? is a red herring: there are presumably one-character-long directories in the Cygwin root directory, so the shell expands /? and runs cmd with switches that happen to produce no output.

Share:
16,637

Related videos on Youtube

Redzarf
Author by

Redzarf

Updated on September 17, 2022

Comments

  • Redzarf
    Redzarf over 1 year

    I'd like to use Cygwin for my main shell at work, but my group uses batch files for several processes. I've been told that I can just do cmd /c batch.bat to run the batch file from Cygwin. This works for some cases, and not for others. One of the batch files completely fails when I do this, but works fine when I run it from the cmd shell.

    Another oddity I've noticed is that if I run cmd /? from Cygwin, I get no output. Running this from the cmd shell gives the standard help. Even doing cmd /c cmd /? provides no output. If I run cmd from Cygwin, it gives me the cmd shell, and then if I run cmd /?, I get the help text, but without the page breaks.

    I guess the next thing to try is to find a way to actually launch cmd within its own distinct window, as if you'd gone to Start->Run, and then typed "cmd". Is there a way to do this from within Cygwin?

  • Michael Mao
    Michael Mao over 13 years
    on my win xp sp2 latop this following code snippet would work: cygstart /cygdrive/c/WINDOWS/system32/cmd
  • eel ghEEz
    eel ghEEz over 7 years
    I needed to paste shell variables into the cmd arguments, so I figured the following could work around Bash and cmd parsers: u='DOMAIN\ACC' p='X<12' r='{Baz 3.1 5-x - (TTT)}' d=$'\"' cmd /c foo.bat -u %d%%u%%d% -p %d%%p%%d% -fooBar %d%%r%%d% -fooBAR true