2017-08-17 5 views
0

を待って:私は、リモートサーバー$fdt_serverリモートコマンドを実行していない - いいえ、これはコードです

cmd.exe /c 'start /B $Rjava_path -jar $Rfdt_path -S 1>> $Rfdt_log_folder\$Rfdt_log_filename.txt 2>>&1' 

を呼び出すために、それが完了するまで待機しない希望

$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 
} 

。 基本的に、私はそれを実行し続けるだけです。

どうすればこの問題を解決できますか?私は-AsJobを使ってみましたが、うまくいかないようです。

+0

try start-processこのコマンドにはwaitパラメータがあります。私はあなたがそれを使用しないと、スクリプトが続行すると思います – guiwhatsthat

+0

@guiwhatsthat、私はStart-Commandを試しました、それはリモートコンピュータでJavaプロセスを一時的に開始し、閉じ、ローカルコンピュータのPowershellスクリプト出口を終了しました。私はPowershellを終了したいが、PSスクリプトを介して遠隔から起動された後は、リモートコンピュータでJavaプロセスを実行したままにしておきたい。私もInvoke-Command-Sessionを使ってみましたが、どちらも動作しません:( – iKnowNothing

答えて

0

Invoke-WmiMethodを使用すると、トリックが発生します。

関連する問題