提问者:小点点

使用基于环境变量的路径运行脚本


我将环境变量artemis_home设置为C:\artemis

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

在这个目录下,我有一个名为bin的文件夹,它包含一个artemis.cmd脚本。如何使用system变量从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

共1个答案

匿名用户

在尝试执行之前,您需要展开该变量并将路径的其余部分串联成一个字符串。要执行结果字符串,请使用&,即调用运算符:

& "$env:ARTEMIS_HOME/bin/artemis.cmd"