最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - subprocess.Popen giving different results when I run it many times - Stack Overflow

programmeradmin1浏览0评论

I am running this code

import subprocess

with open("test.txt", "r") as file:
    cmd = file.readline().strip()


print("test")
print(cmd)

with subprocess.Popen(
        cmd,
        stdout=subprocess.PIPE,
        stdin=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        shell=True,
) as stream:
    # version = streammunicate()[0].decode()
    print(streammunicate()[0])

test.txt is:

powershell -NoProfile "$ErrorActionPreference='silentlycontinue'; $tmp = (Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;}; $tmp = (Get-Item -Path "${env:PROGRAMFILES(x86)}\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;}; $tmp = (Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;};"

and sometimes I get the right result and sometimes I get nothing

This command should return the current chrome version but it just don't sometimes.

发布评论

评论列表(0)

  1. 暂无评论