3
呼叫PowerShell的我打电话从一个命令脚本PS提示符下使用以下行从命令提示符相对路径
powershell "& 'c:/script.ps1'"
不过,我需要的脚本是相对于命令提示符窗口。因此,如果命令提示符看着C:
那么脚本将有效地
powershell "& 'script.ps1'"
是否有办法注入的相对路径?
呼叫PowerShell的我打电话从一个命令脚本PS提示符下使用以下行从命令提示符相对路径
powershell "& 'c:/script.ps1'"
不过,我需要的脚本是相对于命令提示符窗口。因此,如果命令提示符看着C:
那么脚本将有效地
powershell "& 'script.ps1'"
是否有办法注入的相对路径?
powershell "& '%cd%\script.ps1'"
,或者如果你的意思是使用来自该批处理文件是在PowerShell脚本启动目录,那么你会通过把这种类型的线在你的PS脚本的开头使用参数...
param([string]$Directory)
然后在命令行中调用像填充它...
Powershell C:\script.ps1 -Directory %cd%
注入相对路径,你开始你的批处理文件,你必须编写
powershell "& '%~dp0\script.ps1'"
%cd%working - 感谢您的详细回复。 – heymega 2015-02-13 13:33:29