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.
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.
- Go to your Windows Desktop.
- Right click on the desktop and click on New Shortcut
- Don't miss the ending " quotes.
- 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.