如何在批处理文件中使用环境变量

时间:2017-02-16 05:12:32

标签: batch-file cmd environment-variables

我是使用批处理文件的菜鸟

好的,我添加了visstudio系统变量,其值为C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe

所以echo %visstudio%将为我提供cmd中visual studio的路径。

现在我怎么能使用这个变量,以便我可以从我的批处理文件中运行应用程序,我需要这个,因为我有多个项目而且我不想移动文件夹。

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

早些时候我常常喜欢

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

如果我更新Visual Studio,那么我再次需要更改所有批处理文件中的VS路径,并且没人会喜欢。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

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

start将第一个“引用参数”解释为窗口标题。它可以是空的。

可执行文件需要在引号中,因为它包含空格。