[英]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.