简体   繁体   中英

How to open the command prompt from a file

For quick access to the command prompt pointing to a specific directory, I would like to double click on a .bat file (saved on the desktop), and then the command prompt will open pointing to a specific folder, and would like the command prompt to remain open. This is what I did:

rem -changing the drive to e:
e: 
rem - setting the path to the specific folder
cd \users\myName\Documents\folderName\folderName\folderName\

==> this results on the command prompt opening in the specify directory, but closing right away.

I have no problem opening in the 'e' drive (start cmd e: ), but when I specify the path to the folder, it does not work

Is there a way to do this?

You need to use the option /K of the cmd.exe

Please take a look at the following link:

open command prompt window and change current working directory

Hope that helps,

@echo off
cd /d "e:\users\myName\Documents\folderName\folderName\folderName\"
cmd /k
exit

The /K option is the key, as has been said. However, if you want a better CMD environment, considering creating shortcuts to CMD in a desktop folder. By changing the properties of each shortcut, you can then customize the environment, window size, fonts, buffers, etc.

To do this, create a shortcut with a Target something like this:

%windir%\system32\cmd.exe /K C:\Batch\your_batch_file.bat

In your_batch_file.bat, you can set environment variables, paths, select the drive, set the working directory, etc.

By changing the properties of the shortcut, you can totally customize the window size, fonts, colors, buffers, etc.

I use this to set up separate environments for Ruby, JRuby, CMD, etc.

The shortcut properties looks something like 这个 :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM