【发布时间】:2015-02-11 19:14:11
【问题描述】:
我正在使用以下行从命令提示符调用 PS 脚本
powershell "& 'c:/script.ps1'"
但是我需要脚本与命令提示符窗口相关。因此,如果命令提示符正在查看C:,那么该脚本实际上是
powershell "& 'script.ps1'"
有没有办法注入相对路径?
【问题讨论】:
标签: powershell
我正在使用以下行从命令提示符调用 PS 脚本
powershell "& 'c:/script.ps1'"
但是我需要脚本与命令提示符窗口相关。因此,如果命令提示符正在查看C:,那么该脚本实际上是
powershell "& 'script.ps1'"
有没有办法注入相对路径?
【问题讨论】:
标签: powershell
powershell "& '%cd%\script.ps1'"
或者如果您打算使用在 powershell 脚本中启动批处理文件的目录,那么您可以通过将这种类型的行放在 PS 脚本的开头来使用参数...
param([string]$Directory)
然后从命令行调用填充它...
Powershell C:\script.ps1 -Directory %cd%
【讨论】:
要注入相对路径,您必须在其中开始编写批处理文件
powershell "& '%~dp0\script.ps1'"
【讨论】: