0

Possible Duplicate:
Batch file that runs cmd.exe, a command, and then stays open at prompt

I have a set of environmental variables that I have to run before I can run other operations. I have a batch file for these but when I run the batch file it closes at the end. Is there something I can add so it will not close so I can continue to run other operations in the command prompt without writing them into the batch file script itself?

I eventually would like to have a batch file for each operation but I have a lot of different operations I need to run. So for now this will help to avoid the manual work of opening the batch file and copying and pasting the variables into a new command prompt window every time I go to run a new operation.

2 Answers2

1

Run command prompt with the /K switch. This prevents it from closing after the .bat has run


Source: http://ss64.com/nt/cmd.html

Amith KK
  • 205
  • 1
  • 3
  • 13
1

If you need some environment variables set every time that you use the command-prompt, then there are three ways that you can do so:

  • Create the environment variables at the system level, then they will always be available at the command-prompt. You can do this for either a user or the the whole system.

  • Instead of running the batch file directly, create a shortcut to the command-interpreter, passing it the batch-file as an argument, and using the /k switch to keep it open after running:

    %comspec% /k c:\stuff\setenvs.bat
    
  • You can set the Autorun key to automatically run a command whenever you open a command-prompt. Again, you can set it for just a user or the whole system:

    REGEDIT4
    [HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
    "Autorun"="c:\stuff\setenvs.bat"
    
Synetech
  • 68,243
  • 36
  • 223
  • 356