Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #4794

Re: [Python-de] os.system und os.popen

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Sven R. Kunze" <srkunze@mail.de>
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 <mailman.52.1495731968.8815.python-de@python.org> (permalink)
References <c19f4a3f-fcf3-185a-574b-27e7cbeb56aa@fam-goebel.de> <mailman.46.1495726174.8815.python-de@python.org> <eooc7gFaul8U1@mid.individual.net> <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 <srkunze@mail.de>
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 <eooc7gFaul8U1@mid.individual.net>
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 <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <5d4200a7-d838-9135-8aba-17bc4fe8a036@mail.de>
X-Mailman-Original-References <c19f4a3f-fcf3-185a-574b-27e7cbeb56aa@fam-goebel.de> <mailman.46.1495726174.8815.python-de@python.org> <eooc7gFaul8U1@mid.individual.net>
Xref csiph.com de.comp.lang.python:4794

Show key headers only | View raw


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

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[Python-de] os.system und os.popen Ulrich Goebel <ml@fam-goebel.de> - 2017-05-25 17:19 +0200
  Re: [Python-de] os.system und os.popen Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-05-25 17:40 +0200
    Re: [Python-de] os.system und os.popen "Sven R. Kunze" <srkunze@mail.de> - 2017-05-25 19:06 +0200
    Re: [Python-de] os.system und os.popen Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2017-05-25 20:01 +0200
    Re: [Python-de] os.system und os.popen Reimar Bauer <rb.proj@gmail.com> - 2017-05-25 23:30 +0200

csiph-web