One way to view CMD messages while executing an executable through CMD using Python is to use the subprocess
module. Here's an example code snippet:
import subprocess
cmd = 'my_executable.exe arg1 arg2'
# Replace 'my_executable.exe' and 'arg1 arg2' with the actual executable and arguments
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# Read the output line by line as it's generated
while True:
line = p.stdout.readline()
if not line:
break
print(line.strip().decode())
This code snippet creates a new process using the Popen
function from the subprocess
module, passing in the command and arguments as a string, and redirecting both stdout
and stderr
to a pipe. Then it reads the output line by line as it's generated using a loop, printing each line to the console. This way, you can see the CMD messages in real-time as they're generated by the executable.
Asked: 2021-10-18 11:00:00 +0000
Seen: 7 times
Last updated: Sep 07 '22