Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use environment variable in batch file

I am beginner in using batch files.

I have added visstudio system variable with value C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe

So echo %visstudio% will give me the path of Visual Studio in cmd.

Now how could I use this variable so that I can run application from my batch files? I need this as I have multiple projects and I don't want to move in folders.

@echo off
start %visstudio% "%cd%\Src\Edge\Test\Edge.Test.sln"

Earlier I used to do like:

@echo off
start "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" "%cd%\Src\Edge\Test\Edge.Test.sln"

If I update Visual Studio then I again need to change the VS paths in all batch files, and that nobody will like.

like image 695
A.T. Avatar asked Apr 09 '26 22:04

A.T.


1 Answers

start "window name - can be empty but not omitted" "%visstudio%" "%cd%\Src\Edge\Test\Edge.Test.sln"

start interprets the first "quoted parameter" as a window title. It can be empty.

The executable needs to be in quotes since it contains spaces.

like image 70
Magoo Avatar answered Apr 12 '26 21:04

Magoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!