0

Trying to execute a .bat file from a shell script. This .bat file calls another .bat file.

The first bat file contains:

other_file.bat -c some_conf.xml

This means I cannot do:

start dir/my_file

But I need to do:

cd dir
cmd /k $(cat my_file)

But the command in my_file is not executed. I tried

cmd /k other_file.bat -c some_conf.xml

cmd /k "other_file.bat -c some_conf.xml"

None of these worked. But if i do cmd /k then enter manually other_file.bat -c some_conf.xml, it works...

| |
  • 2
    Is this running in the Windows subsystem for Linux on Windows? I don't know what cmd /k does, it's not a Unix command... – Kusalananda Mar 11 '19 at 10:42
  • It's running under MINGW64, on windows but it tries to replicate a linux shell if i understood correctly. – JustADude Mar 11 '19 at 10:52
  • @Kusalananda cmd /k string Carries out the command specified by string but remains. Its inverse is cmd /c which is the analog of bash -c – phuclv Mar 11 '19 at 12:49
0

This problem has nothing to do with Unix.

There is clearly a bug with MINGW64 stopping it from passing the cmd.exe command line correctly. It is trying to be super tricky thinking that /K must be a path.

Either use a dash or double the forward slash:

cmd.exe //k other_file.bat -c some_conf.xml
cmd.exe -k other_file.bat -c some_conf.xml

How on earth did I know this (you might ask)?

If you look at the cmd.exe process that MINGW64 spawned, the command line looks like this:

C:\WINDOWS\system32\cmd.exe K:/ other_file.bat -c some_conf.xml

See the K:/?

| |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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