Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Sven R. Kunze" Newsgroups: de.comp.lang.python Subject: Re: [Python-de] os.system und os.popen Date: Thu, 25 May 2017 19:06:05 +0200 Lines: 39 Message-ID: References: <5d4200a7-d838-9135-8aba-17bc4fe8a036@mail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de 3fzJmsPyd+w8y67M2Ldpdw9dfvvzC88Q8I//MDN/e6KQ== Return-Path: X-Original-To: python-de@python.org Delivered-To: python-de@mail.python.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde201610; t=1495731966; bh=n8U9zaEgMEq8+P+MKIRbkwx2wer2HmKisjOXHZ6raw0=; h=Subject:To:References:From:Date:In-Reply-To:From; b=duIrt+kH33Gux68DArqHC2bymj60TqkiyT99m9LUfkkHNwqGFhcWJuQrGGf+g4fz7 +k5jKovB+hljX4xXSEjxhGgdQ4FrEMvNUvjZ+RDx7YBiSarleD+sj9eoCPeHpxyM+Z /XvIgn7QGY3MGe7OYAj+XYGVW9c39+DT5nojfpQI= In-Reply-To: Content-Language: en-US X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 3187 X-purgate-ID: 154282::1495731966-0000088C-894EBB52/0/0 X-Spam-Status: No, score=-2.9 required=10.0 tests=ALL_TRUSTED,BAYES_00, FREEMAIL_FROM,HTML_MESSAGE autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on spamassassin01.mail.de X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: python-de@python.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Die Deutsche Python Mailingliste List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <5d4200a7-d838-9135-8aba-17bc4fe8a036@mail.de> X-Mailman-Original-References: Xref: csiph.com de.comp.lang.python:4794 On 25.05.2017 17:40, Hermann Riemann wrote: > error=os.system("latex ... 2> /tmp/log") > > Hermann > der das so machen würde > Sieht durchaus einfacher aus, ist aber nicht ganz unsicher, wenn's um das Thema Quoting von Parametern geht. *Hier auch noch zum Nachlesen:* https://docs.python.org/3.6/library/subprocess.html The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module *intends to replace* several older modules and functions: os.system os.spawn* *Überspitzt ausgedrückt:* subprocess ist der neue heiße Scheiß und os.system/os.popen der Schnee von gestern. ;-) Daher empfehle auch ich, wie Volker: try: output = subprocess.check_output(.......) except subprocess.CalledProcessError as exc: # hier geht's zur Fehlerbehandlung, falls latex streikt print(exc.output) else: # alles gut print(output) Das funktioniert sowohl unter Python 2 als auch Python 3. Viel Erfolg damit. :) Grüße, Sven