PowerShell:从powershell中运行命令行应用程序

时间:2015-12-10 18:18:49

标签: powershell cmd command-line-interface

假设我在beforeAll(function() { itemsArr = [ { name: 'apple' }, { name: 'orange' }, { name: 'banana' } ] }); 文件夹中有一个Windows命令行应用程序(abc.exe)。 我也将我的powershell脚本文件放在同一个位置。

通过使用此命令,我将当前位置设置为启动脚本的位置:

C:\test

我需要在我的脚本中运行Set-Location $PSScriptRoot ,以便在我的脚本的执行窗口中按Control + C,它也会终止abc.exe

如果我在我的脚本中使用这种语法:abc.exe,那么一切都符合我的要求。但问题是我不想在我的脚本中硬编码C:\test\abc.exe的位置,因为用户可能会更改它。(注意: abc.exe将始终是在与我的脚本相同的位置)

如果我只使用:abc.exe我会得到:

abc.exe

我该怎么办?

更新:在Windows批处理脚本中,在这种情况下按Control + C将很容易终止脚本和命令行应用程序的执行

1 个答案:

答案 0 :(得分:0)

你试试这个......

Start-Process -PSPath "C:\test\abc.exe" -WorkingDirectory "C:\test" -NoNewWindow

第二个建议:

Start-Process -PSPath "C:\test\abc.exe" -WorkingDirectory "C:\test" -NoNewWindow -Wait
相关问题