0
這是代碼:遠程執行命令 - 無等待
$remotelastexitcode = Invoke-Command -ComputerName $fdt_server -Credential $Cred -ScriptBlock {
Param($Rjava_path, $Rfdt_path, $Rfdt_log_folder, $Rfdt_log_filename)
Invoke-Expression -Command:"cmd.exe /c 'start /B $Rjava_path -jar $Rfdt_path -S 1>> $Rfdt_log_folder\$Rfdt_log_filename.txt 2>>&1 & exit 0'";
$LASTEXITCODE
} -ArgumentList $java_path, $fdt_path, $fdt_log_folder, $fdt_log_filename -ErrorAction Stop
# Force the result to an array, and then test just the last line, which will be
# the last exit code. Anything echoed before that will be ignored.
if (@($remotelastexitcode)[-1] -ne 0) {
exit 1
}
我想援引
cmd.exe /c 'start /B $Rjava_path -jar $Rfdt_path -S 1>> $Rfdt_log_folder\$Rfdt_log_filename.txt 2>>&1'
遠程服務器$fdt_server
上,而不是等待它完成。基本上,我希望它只是運行它,並繼續前進。
我該如何做到這一點?我嘗試使用-AsJob
,但似乎沒有工作。
嘗試啓動進程,該命令有一個等待參數。我想當你不使用它時,腳本將繼續運行 – guiwhatsthat
@guiwhatsthat,我試過Start-Command,它在遠程計算機中暫時啓動了java進程,然後關閉,Powershell腳本在本地計算機中退出。我想讓Powershell退出,但是通過PS腳本遠程啓動後,Java程序會在遠程計算機上運行。我也嘗試使用Invoke-Command -Session,也不能工作:( – iKnowNothing