0

I am making a GUI aplplication in Python that requires to run a cmd prompt command.

e. g.:

import subprocess
subprocess.Popen("arp -a > arptable.txt",stdin=PIPE, stdout=PIPE,shell=Ture)

Now, after running this command, I see a small splash of cmd screen, and a text file containing the arp table is generated. In my application, I don't want this black screen to splash, so that the user doesn't know there's a cmd prompt involved in the appplication.

How can I do this?

4

2 回答 2

0

在 Windows 上,您需要将一个STARTUPINFO类传递给startupinfoofsubprocess.Popen来实现这一点。要使其便携:

import subprocess
import os

si = None
if os.name == 'nt':
    si = subprocess.STARTUPINFO()
    si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen("arp -a > arptable.txt",stdin=PIPE, stdout=PIPE, startupinfo=si)
于 2012-12-27T22:13:06.317 回答
0

你不需要shell=True

import os
from subprocess import PIPE, STDOUT, check_call

with open("arptable.txt", "rb") as file, open(os.devnull, "r+b") as devnull:
    check_call(["arp", "-a"], stdin=devnull, stdout=file, stderr=STDOUT)
于 2012-12-27T21:58:21.337 回答