簡體   English   中英

PowerShell:在Powershell中運行命令行應用程序

[英]PowerShell: run command line application from within powershell

假設我在以下位置有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會很容易地終止腳本和命令行應用程序的執行

您嘗試過這個嗎?

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

第二個建議:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM