de.comp.lang.python
  Home FAQ Contact Sign in
de.comp.lang.python only
 
Advanced search
February 2008
motuwethfrsasuw
    123 5
45678910 6
11121314151617 7
18192021222324 8
2526272829   9
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
de.comp.lang.python Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  os.system         


Author: Brot
Date: Feb 17, 2008 03:17

Hallo,

ich möchte ein linux-commando von python aus aufrufen. Dazu gibt es
jetzt os.system. Das Problem ist aber, dass ich gerne die Ausgabe des
Programmes in einer Variable hätte.
os.system liefert mir aber "nur" den exit-code zurück. Wie kann ich
jetzt die Kommandoausgabe in eine Variable schreiben?

import os
test = os.system('ls -l | wc -w')
print test

'test' liefert mir jetzt 0 (exit code). Aber ich möchte das Ergebnis
des Befehls in einer Variable.
Kann mir hier jemand weiter helfen?

lgr
Bernd
2 Comments