Çok özel bir soru (umarım): Aşağıdaki üç kod arasındaki farklar nelerdir?Python alt işlemi Popen.communicate() ile Popen.stdout.read() öğesine eşdeğerdir?
(Ben ikinci ve üçüncü olanlar yaparken alt sürecin beklemez ilk bitirilmesi sadece olmasını bekliyoruz. Ama bu sadece fark olduğundan emin olmak gerekir ... zaten ben zaten Python subprocess interaction, why does my process work with Popen.communicate, but not Popen.stdout.read()? okumanızı ve ben istemiyorum shell=True
tehlikeler ve platformlar arası sınırlamalar)
not iyi biliyorum gerçi)
Ben de/etkileşim diğer açıklamalar/öneriler (ihtiyaç hoş geldiniz sonra program ile.
Ayrıca zaten Alternatives to Python Popen.communicate() memory limitations? okumak ama unutmayın ben gerçekten ... alamadım o
Nihayet, bir yerlerde bir tampon bir çıkış ile doldurulur çıkmaz riski vardır farkındayım notu ... bir yöntemi kullanarak fakat internette net açıklamalar için seyir sırasında kayboldu
İlk kod:
from subprocess import Popen, PIPE
def exe_f(command='ls -l', shell=True):
"""Function to execute a command and return stuff"""
process = Popen(command, shell=shell, stdout=PIPE, stderr=PIPE)
stdout = process.stdout.read()
stderr = process.stderr.read()
return process, stderr, stdout
İkinci kod:
from subprocess import Popen, PIPE
from subprocess import communicate
def exe_f(command='ls -l', shell=True):
"""Function to execute a command and return stuff"""
process = Popen(command, shell=shell, stdout=PIPE, stderr=PIPE)
(stdout, stderr) = process.communicate()
return process, stderr, stdout
Üçüncü kodu:
from subprocess import Popen, PIPE
from subprocess import wait
def exe_f(command='ls -l', shell=True):
"""Function to execute a command and return stuff"""
process = Popen(command, shell=shell, stdout=PIPE, stderr=PIPE)
code = process.wait()
stdout = process.stdout.read()
stderr = process.stderr.read()
return process, stderr, stdout
teşekkürler. Eğer subprocess.communicate()
için kaynak bakarsak