Запустить скрипт с путем, основанным на переменной среды

У меня переменная среды ARTEMIS_HOME установлена ​​на c:\artemis.

PS C:\artemis_brokers> $env:ARTEMIS_HOME
C:\artemis

В этом каталоге у меня есть папка bin, содержащая сценарий artemis.cmd. Как я могу запустить этот скрипт из любого места в моей PowerShell, используя системную переменную?

Я безуспешно пробовал следующее:

PS C:\artemis_brokers> $env:ARTEMIS_HOME/bin/artemis
At line:1 char:19
+ $env:ARTEMIS_HOME/bin/artemis
+                   ~
You must provide a value expression following the '/' operator.
At line:1 char:19
+ $env:ARTEMIS_HOME/bin/artemis
+                   ~~~~~~~~~~~
Unexpected token 'bin/artemis' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression
PS C:\artemis_brokers> ./$env:ARTEMIS_HOME/bin/artemis
./$env:ARTEMIS_HOME/bin/artemis : The term './$env:ARTEMIS_HOME/bin/artemis'
is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ ./$env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> ./$env:ARTEMIS_HOME/bin/artemis.cmd
./$env:ARTEMIS_HOME/bin/artemis.cmd : The term './$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ ./$env:ARTEMIS_HOME/bin/artemis.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> ./"$env:ARTEMIS_HOME/bin/artemis.cmd"
./$env:ARTEMIS_HOME/bin/artemis.cmd : The term './$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ ./"$env:ARTEMIS_HOME/bin/artemis.cmd"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\$env:ARTEMIS_HOME/bin/artemis
.\$env:ARTEMIS_HOME/bin/artemis : The term '.\$env:ARTEMIS_HOME/bin/artemis'
is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ .\$env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\$env:ARTEMIS_HOME/bin/artemis.cmd
.\$env:ARTEMIS_HOME/bin/artemis.cmd : The term '.\$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ .\$env:ARTEMIS_HOME/bin/artemis.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\"$env:ARTEMIS_HOME/bin/artemis.cmd"
.\$env:ARTEMIS_HOME/bin/artemis.cmd : The term '.\$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ .\"$env:ARTEMIS_HOME/bin/artemis.cmd"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

person João Menighin    schedule 30.11.2018    source источник
comment
просто сделай cmd.exe /c "$env:ARTEMIS_HOME\bin\artemis.cmd"   -  person Theo    schedule 30.11.2018


Ответы (2)


Перед попыткой выполнения необходимо развернуть переменную и объединить оставшуюся часть пути в строку. Чтобы выполнить полученную строку, используйте &, оператор вызова:

& "$env:ARTEMIS_HOME/bin/artemis.cmd"
person zdan    schedule 30.11.2018

Пытаться:

& $env:ARTEMIS_HOME\bin\artemis.cmd
person nicholas79171    schedule 30.11.2018