1
我嘗試執行PowerShell命令來獲取內存使用情況並獲得結果。Python執行powershell命令
import subprocess
output = subprocess.call(["powershell.exe", "Get-Counter -Counter "+'"\memory\\available mbytes"'+" -MaxSamples 10 -SampleInterval 1"])
try:
subprocess.check_output("Get-Counter -Counter "+'"\memory\\available mbytes"'+" -MaxSamples 10 -SampleInterval 1", shell=TRUE)
except subprocess.CalledProcessError, e:
print "subproces CalledProcessError.output = " + e.output
print output
這是成功執行命令,但只得到以下結果:
subproces CalledProcessError.output =
0
我怎樣才能獲得PowerShell的結果回來?
請問您的命令('找櫃檯-Counter 「\內存\可用兆字節」 -MaxSamples 10 -SampleInterval 1')在交互式工作PowerShell會話? –