开发者

How to call a .bat file from any location in CMD on Windows

I have a Batch file which I want to execute in 开发者_StackOverflow中文版CMD from any directory. Something like this:

File name: MyBatch

Path: C:\MyBatch.bat

Open CMD: c:\Program Files> MyBatch

How can I accomplish this?


Set that location in your PATH environmental variable.

I wouldn't put it the root or the system directory.

I keep a directory with all my scripts in C:\DRR\CMD

and either set it in the MyComputer GUI or run at the command script:

set PATH=%PATH%;C:\DRR\CMD


You could just put it in your c:\windows\system32 directory, as its always in the system path.


How about... "%MyBatch%"? (the double qoutes are intended)

That should work!

to change your Variable, use set MyBatch="Path\Whatever.bat"

and to ask the user for a String, use set /p MyBatch="Question? "
-- or, you can use a BAT-to-EXE converter to run the batch in a Executable.


You would need to set the PATH environment variable to include the path to your batch file


If you are talking Windows, then the PATH Environment variable is what you need to set.

The path where your bat file is placed should be appended to the PATH variable. In your example append "C:\;" in the value for Path environment variable.

Then you can execute MyBatch.bat from anywhere on the command line.


Create a folder called Batches (lets say in your C drive).

Append C:\Batches in your path environment variable and you then can run batch files in that directory from anywhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜