Установите переменную пути с пробелами в пути в Windows .cmd файл или пакетный файл

В то время как я думаю, лучше избегать goto почти на любой ситуации, существуют исключения. Например, одно место, которое я видел, где операторы перехода являются изящным решением по сравнению с другими намного более замысловатые пути, реализует последний вызов elimintation для интерпретатора.

100
задан marcerickson 5 December 2009 в 03:08
поделиться

2 ответа

Try something like this:

SET MY_PATH=C:\Folder with a space

"%MY_PATH%\MyProgram.exe" /switch1 /switch2
92
ответ дан 24 November 2019 в 04:50
поделиться

There are two options here. First, you can store the path unquoted and just quote it later:

set MyPath=C:\Program Files\Foo
"%MyPath%\foo with spaces.exe" something

Another option you could use is a subroutine which alles for un-quoting strings (but in this case it's actually not a very good idea since you're adding quotes, stripping them away and re-adding them again without benefit):

set MyPath="C:\Program Files\Foo"
call :foo %MyPath%
goto :eof

:foo
"%~1\foo.exe"
goto :eof

The %~1 removes quotation marks around the argument. This comes in handy when passing folder names around quoted but, as said before, in this particular case it's not the best idea :-)

31
ответ дан 24 November 2019 в 04:50
поделиться
Другие вопросы по тегам:

Похожие вопросы: