簡體   English   中英

python多執行命令

[英]python multiple execute command

import subprocess

command = r'C:\Windows\system32\windowspowershell\v1.0\powershell.exe -noe -c ". \"C:\Program Files\VMware\VMware View\Server\extras\PowerShell\add-snapin.ps1\""'
command2 = 'Get-PoolEntitlement -pool_id gameserver2 | Remove-
PoolEntitlement'
output = subprocess.getoutput(command)
output = subprocess.getoutput(command2)
print(output)

我已經運行了多個與命令相關的命令。 但是我不

錯誤:

'Get-PoolEntitlement' is not recognized as an internal or external command,

可操作的程序或批處理文件。

如果您需要一次執行多個cmd命令,則可以在它們之間加上“ &&”。

例如, cd documents&&start會導航到documents文件夾並啟動一個新的命令提示符,希望這會有所幫助

在第一個命令中,您正在調用PowerShell:

command = r'C:\Windows\system32\windowspowershell\v1.0\powershell.exe -noe -c ". \"C:\Program Files\VMware\VMware View\Server\extras\PowerShell\add-snapin.ps1\""'

在第二個你不是!

command2 = 'Get-PoolEntitlement -pool_id gameserver2 | Remove-PoolEntitlement'

因此,您只需要像這樣糾正即可:

command2 = r'C:\Windows\system32\windowspowershell\v1.0\powershell.exe -noe -c "Get-PoolEntitlement -pool_id gameserver2 | Remove-PoolEntitlement"'

暫無
暫無

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

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