“Cómo capturar la salida de CMD en Python” Código de respuesta

Ejecutar el comando y obtener salidas python

# You can use following commands to run any shell command. I have used them on ubuntu.

import os
os.popen('your command here').read()

# Note: This is deprecated since python 2.6. Now you must use subprocess.Popen. Below is the example

import subprocess

p = subprocess.Popen("Your command", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
print p.split("\n")
Merwanski

Python ejecutar el comando shell y obtener salida

import subprocess
process = subprocess.Popen(['echo', 'More output'],
                     stdout=subprocess.PIPE, 
                     stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
stdout, stderr
Kaotik

comando de ejecución de python y salida de lectura

>>> subprocess.check_output(['ls', '-l'])
b'total 0\n-rw-r--r--  1 memyself  staff  0 Mar 14 11:04 files\n'
Bloody Baboon

Cómo capturar la salida de CMD en Python

from subprocess import Popen, PIPE
path = "echo"
pipe = Popen(path, stdout=PIPE)
text, err = pipe.communicate()
if(pipe.returncode==0)
print( text, err)
Falcon Shaheen

Respuestas similares a “Cómo capturar la salida de CMD en Python”

Preguntas similares a “Cómo capturar la salida de CMD en Python”

Más respuestas relacionadas con “Cómo capturar la salida de CMD en Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código