我有以下几点,非常好用
ps1
脚本:
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$currentDir = Get-ScriptDirectory
node $currentDir/yarn.js $args
我想消除
$currentDir
变量。我想跑:
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
node (Get-ScriptDirectory)/yarn.js $args
但这失败了-看起来
Get-ScriptDirectory
输出成为第一个参数。我试过用引号,但也不起作用-括号不再扩展。
如何使用函数的输出运行命令?