“Python Execute Shell -Befehl und Ausgabe erhalten” Code-Antworten

Befehl ausführen und Ausgabe Python erhalten

# 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 Execute Shell -Befehl und Ausgabe erhalten

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

Führen Sie den Befehl Linux mit Python aus

import subprocess
subprocess.call("command1")
subprocess.call(["command1", "arg1", "arg2"])
Sachin

Python Run -Befehl und lesen Sie die Ausgabe ab

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

Ähnliche Antworten wie “Python Execute Shell -Befehl und Ausgabe erhalten”

Fragen ähnlich wie “Python Execute Shell -Befehl und Ausgabe erhalten”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen