Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #4789 > unrolled thread
| Started by | Ulrich Goebel <ml@fam-goebel.de> |
|---|---|
| First post | 2017-05-25 17:19 +0200 |
| Last post | 2017-05-25 23:30 +0200 |
| Articles | 5 — 5 participants |
Back to article view | Back to de.comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[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
| From | Ulrich Goebel <ml@fam-goebel.de> |
|---|---|
| Date | 2017-05-25 17:19 +0200 |
| Subject | [Python-de] os.system und os.popen |
| Message-ID | <mailman.46.1495726174.8815.python-de@python.org> |
Hallo,
ich möchte mit
error=os.system("latex ...") LaTeX oder andere Befehle aufrufen. Im
Falle, dass der Befehl mit einem Code != 0 (error != 0) endet, möchte
ich gerne die Ausgaben des Befehls sehen, also das Ergebnis von
log=os.popen("latex ...")
Geht das?
Mit Dank und Gruß
Ulrich
--
Ulrich Goebel
Am Büchel 57, 53173 Bonn
[toc] | [next] | [standalone]
| From | Hermann Riemann <nospam.ng@hermann-riemann.de> |
|---|---|
| Date | 2017-05-25 17:40 +0200 |
| Message-ID | <eooc7gFaul8U1@mid.individual.net> |
| In reply to | #4789 |
Am 25.05.2017 um 17:19 schrieb Ulrich Goebel:
> ich möchte mit
> error=os.system("latex ...") LaTeX oder andere Befehle aufrufen. Im
> Falle, dass der Befehl mit einem Code != 0 (error != 0) endet, möchte
> ich gerne die Ausgaben des Befehls sehen, also das Ergebnis von
> log=os.popen("latex ...")
> Geht das?
error=os.system("latex ... 2> /tmp/log")
Hermann
der das so machen würde
--
http://www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | "Sven R. Kunze" <srkunze@mail.de> |
|---|---|
| Date | 2017-05-25 19:06 +0200 |
| Message-ID | <mailman.52.1495731968.8815.python-de@python.org> |
| In reply to | #4791 |
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
[toc] | [prev] | [next] | [standalone]
| From | Stefan Schwarzer <sschwarzer@sschwarzer.net> |
|---|---|
| Date | 2017-05-25 20:01 +0200 |
| Message-ID | <mailman.55.1495736107.8815.python-de@python.org> |
| In reply to | #4791 |
On 2017-05-25 19:06, Sven R. Kunze wrote:> 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
`subprocess` ist nicht nur sicherer, sondern auch ganz
allgemein robuster.
Es wird zwar immer hervorgehoben, dass mit dem Modul keine
Angriffe mit speziellen Dateinamen möglich sind (was stimmt),
aber das Modul hilft auch, wenn zum Beispiel Dateinamen ganz
ohne böse Absicht Leerzeichen enthalten oder Zeichen, die
sonst von der Shell interpretiert werden würden.
Beispiel:
dateiname = "dies & das.txt" # von irgendwoher
ausgabe = subprocess.check_output(["du", "--human-readable", "--summarize", dateiname])
Viele Grüße
Stefan
[toc] | [prev] | [next] | [standalone]
| From | Reimar Bauer <rb.proj@gmail.com> |
|---|---|
| Date | 2017-05-25 23:30 +0200 |
| Message-ID | <mailman.9.1495747827.13056.python-de@python.org> |
| In reply to | #4791 |
Ich hab letztens noch EasyProcess kennen gelernt.
https://pypi.python.org/pypi/EasyProcess
Viele Grüße
Reimar
2017-05-25 20:01 GMT+02:00 Stefan Schwarzer <sschwarzer@sschwarzer.net>:
> On 2017-05-25 19:06, Sven R. Kunze wrote:> 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
>
> `subprocess` ist nicht nur sicherer, sondern auch ganz
> allgemein robuster.
>
> Es wird zwar immer hervorgehoben, dass mit dem Modul keine
> Angriffe mit speziellen Dateinamen möglich sind (was stimmt),
> aber das Modul hilft auch, wenn zum Beispiel Dateinamen ganz
> ohne böse Absicht Leerzeichen enthalten oder Zeichen, die
> sonst von der Shell interpretiert werden würden.
>
> Beispiel:
>
> dateiname = "dies & das.txt" # von irgendwoher
>
> ausgabe = subprocess.check_output(["du", "--human-readable",
> "--summarize", dateiname])
>
> Viele Grüße
> Stefan
> _______________________________________________
> python-de maillist - python-de@python.org
> https://mail.python.org/mailman/listinfo/python-de
>
[toc] | [prev] | [standalone]
Back to top | Article view | de.comp.lang.python
csiph-web