I wanted to get display card information on windows via dxdiag so I used following code:

import os, sys, subprocess

b = open(os.environ["TMP"] +"\\dx_info.bat", "w")
cmd = r'''@ECHO OFF
SETLOCAL
dxdiag /x dx_temp.xml
DEL "%~f0"'''
b.write(cmd)
b.close()

os.chdir(os.environ["TMP"])

subprocess.call([os.environ["TMP"] +"\\dx_info.bat"])

this script creates a bat file in %Temp% then runs it and waits for command to complete and create dx_temp.xml. But in some PCs, after running dxdiag, a prompt dialog box stops the command from continuing. In this situation an endless wait for command completion occurs. How can I force subprocess.call to skip all those prompts?

Python 2.7.6 on windows 8

有帮助吗?

解决方案

subprocess can only launch other processes. It can't tell those other processes what to do with that (beyond allowing you to pass data via STDIN).

dxdiag is generating those dialog internally, outside of subprocess' realm of control.

The only way to reliably stop it is to figure out what dialog is popping up and find a flag specific to dxdiag to disable that dialog (if one exists).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top