假设我有一个 Windows 命令行应用程序(
通过使用此命令,我将当前位置设置为从其中启动脚本的位置:
我需要在我的脚本中运行
如果我在我的脚本中使用这个语法:
如果我只是使用:
abc.exe
)在:C:\test
文件夹中。
我也将我的 PowerShell 脚本文件放在同一位置。通过使用此命令,我将当前位置设置为从其中启动脚本的位置:
Set-Location $PSScriptRoot
我需要在我的脚本中运行
abc.exe
,这样当我按下脚本执行窗口中的Control+C时,它也会终止abc.exe
。如果我在我的脚本中使用这个语法:
C:\test\abc.exe
,一切都是我想要的。但问题在于我不想在我的脚本中硬编码abc.exe
的位置,因为用户可能会更改它。(注意:abc.exe
将始终在与我的脚本相同的位置)如果我只是使用:
abc.exe
,我会得到:& : The term 'abc.exe' 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.
我该怎么办?
更新:在Windows批处理脚本中,按下Control+C将轻松终止脚本和命令行应用程序的执行。
.\abc.exe
。 - Bacon Bits