Home > Blockchain >  cmd console run in background
cmd console run in background

Time:10-09

Okay so I'm working to get cmd prompt to run code without the user noticing most likely will be creating a list of prompts that determine which command is run. The closest I've come so far is using subprocess which as far as I can tell won't work. So what I've been able to get subprocess to do is allow the command(s) to be written without the cmd console however, it's just using the python console.

The goal I am aiming for is to have buttons a user will click that based on the gathered information will run a code i.e. no internet check the nic via "ping ::1" <- in cmd(but without the cmd console showing up or rather the user needing to do anything (beyond the prompts) and seeing as little as possible). It would then store that information for the rest of the applications use possibly never showing the information to the user as it is expected they will not understand nor will they know what to do with the information. I do need the information stored so if needed it can be accessed by someone who can make use of the information.

import subprocess
subprocess.run('cmd', shell=True)

from here in the python console you are able to type whatever command.

CodePudding user response:

The subprocess.run already executes a terminal command. You don't need to call the cmd. And, it won't pop a screen.

To better undestand, try this:

import subprocess
subprocess.run('echo "Hello World!"', shell=True)

It outputs:

"Hello World!"
CompletedProcess(args='echo "Hello World!"', returncode=0)

It also has options for capturing the output, but for what you are trying to do, this might do.

  • Related