[英]Python calling Powershell commands
我正在構建一個調用 Powershell 來獲取數據的 API。
當我使用subprocess.check_output運行命令時,除了“*”外,一切正常
powershell_call = json.loads(subprocess.check_output([
'powershell.exe',
f'{cmdlet_name} -Identity "{identity}" -Server {server} -Properties * | ConvertTo-Json -Depth {jsonDepth}'
]))
錯誤信息:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 8110: invalid start byte
我試圖將調用方法更改為:
powershell_call = subprocess.Popen(
[
"powershell.exe",
f'{cmdlet_name} -Identity "{identity}" -Server {server} -Properties * | ConvertTo-Json -Depth {jsonDepth}'
],
shell=True,
stdout = subprocess.PIPE,
encoding = 'utf-8',
universal_newlines = True
)
但它給出了相同的錯誤信息。
有沒有辦法在通過子進程調用 PowerShell 時傳遞星號字符?
- - 編輯 - -
原來,我只是需要改變subprocess.check_output到subprocess.getoutput
原來,我只是需要改變subprocess.check_output到subprocess.getoutput
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.