This guide will help to launch Windows Command Prompt with custom environment variables. Sometimes we need to launch command line with custom environment variables. This guide will create a shortcut to launch set custom environment variables.


Even though it is an old question but still I find lots of people querying about it. Basically,

Our primary goal is to Launch Command Line Prompt with Custom Environment Variables and PREVENT command line from auto exiting!.

We'll using here /k switch of cmd. You can read more about it by typing cmd /? in command prompt. I'm also pasting its snapshot to show the relevant part where it mentions the word remains which means persistent with the session. Here is the snapshot.

enter image description here

Method 1: Launch Command Line with Inline Environment Declarations

In this method you need to create a shortcut (or run from RUN command) with your custom environment variables using && operator. Here this && denotes AND analogy that we studied in programming.

  1. Go to your Windows Desktop.
  2. Right click on the desktop and click on New Shortcut
  3. Snapshot 1 of 2 of a typical shortcut with inline variables
  4. Don't miss the ending " quotes. Snapshot 2 of 2 of a typical shortcut with inline variables
  5. In the shortcut paste the following line. To demonstrate an example I'm here setting up some custom environment parameters to launch my ruby enabled command line. C:\Windows\System32\cmd.exe /k "set RUBYOPT=-E utf-8 && set SSL_CERT_File=c:\Ruby22\cacert.pem". Please note that we writing the command environments in a Single Line by using && operator. You can repeat && any number of times you want. Now save the Shortcut with any name and double click it to see the environment set.

Method 2: Setting Up Custom Environment Paths from a different batch file (.bat)

  1. Create a batch file with any name. In this example we'll call it launch.bat and save it to c:\launches\launch.bat. enter image description here
  2. Now Create a shortcut (like explained in method 1) or run it via Windows + R command with the following parameters.
  3. C:\Windows\System32\cmd.exe /k "c:\launches\launch.bat".
  4. Launching Command Line from Environment Variables from a different batch file
    1. Launching Command Line from Environment Variables from a different batch file after launch
|improve this answer|||||

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.