Search code examples
batch-filecommand-linecmdexecutablecd

How do I send commands in a batch file to a command line .exe?


I am vaguely familiar with batch. Super light knowledge. Anyways, I have this program that runs in a command line mode (it happens to render minecraft maps). It is normally used by opening cmd, and typing mapcrafter.exe -c config.config -j 8 which runs the exe, specifies the config file, and runs the job with 8 threads.

One thing I wanted to do was put all of this in a batch file so I didn't have to type everything in every time I wanted to re-render it. It looked like:

start cmd.exe /K mapcrafter.exe --config "config.config" --jobs 8

This worked great, when the batch file was in the same directory as the exe. Anyways, what I don't know how to do is to:

  1. Start command prompt
  2. change directory (cd) to the folder containing the .exe
  3. Run the .exe with the two (-c -j) parameters

I want to do all of this in one batch file, and I want it to keep the command prompt window open, since the .exe outputs errors and percent completion.

I'm lucky I was able to get the one-line batch file working, with my limited knowledge of batch. At this point, I'm out of ideas as to how I should approach this. Thank you in advance for any help you can offer!


Solution

  • Why don't you just create a batch file with

    mapcrafter.exe --config "config.config" --jobs 8
    

    The reason it doesn't work when it is not in the same directory is because your path variable doesn't have the location of mapcrafter. An easier way around would be to use full path something like

    D:\MineCraft\mapcrafter.exe --config "config.config" --jobs 8
    

    If you want to learn more about configuring PATH environment variable see Adding directory to PATH Environment Variable in Windows