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

From "Sven R. Kunze" <srkunze@mail.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] os.system und os.popen
Date 2017-05-25 19:06 +0200
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>

Show all headers | 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