Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by heavyd, slhck Oct 29 '12 at 20:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
How are you opening the command-prompt/running the batch-file. There are at least three ways that this can be solved depending on your circumstances. –  Synetech Oct 29 '12 at 18:37
    
I am running the batch file from windows explorer window. –  Shenanigans Oct 29 '12 at 18:45
add comment

2 Answers

up vote 1 down vote accepted

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"
    
share|improve this answer
    
Awesome, I got the /K switch working. Thank you so much. You just made my life soo much easier. –  Shenanigans Oct 29 '12 at 18:59
add comment

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


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

share|improve this answer
add comment

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