亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過Powershell異步從遠程機器運行Python腳本?

如何通過Powershell異步從遠程機器運行Python腳本?

哈士奇WWW 2021-08-24 14:50:40
我有一個只能同步工作的 powershell 函數。我想更新這個函數,以便我可以并行觸發對 Python 腳本的多個調用。有沒有人知道如何使用 powershell 異步調用 Python 腳本,記住每個 Python 腳本本質上都是一個 while 循環,直到 24 小時后才結束。powershell 函數接收遠程機器、python 虛擬環境、python 腳本的路徑和參數。以下是迄今為止所做的工作:function Run-Remote($computerName, $pname, $scriptPath, $pargs){    $cred = Get-QRemote-Credential    Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock {powershell -c "$Using:pname '$Using:scriptPath' $Using:pargs"} -ConfigurationName QRemoteConfiguration}
查看完整描述

1 回答

?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

修復非常簡單,只需在調用命令中添加“-AsJob”即可。這將使 powershell 為您發送的每個命令啟動一個新進程。然后在腳本末尾使用“Get-Job | Wait-Job”等待所有進程完成。和“Get-Job | Receive-Job”來取回任何數據。


我建議閱讀有關 powershell 的工作,它們非常有用但不直觀。


function Run-Remote($computerName, $pname, $scriptPath, $pargs)

{

    $cred = Get-QRemote-Credential

    Invoke-Command -AsJob -ComputerName $computerName -Credential $cred -ScriptBlock {powershell -c "$Using:pname '$Using:scriptPath' $Using:pargs"} -ConfigurationName QRemoteConfiguration

}


Get-Job | Wait-Job


查看完整回答
反對 回復 2021-08-24
  • 1 回答
  • 0 關注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號