To find out why the problem occurred, try running the script
python webls.py > output
output . , Content-type: text/html , , , .
- , outout os.system Python- ( : print(...) , , os.system() os.system transacton, ( , outout )). , .
import cgi
import os
import sys
print 'Content-type: text/html'
print ''
sys.stdout.flush()
os.system('ls')
, , - , - os.system. , . ( ):
- /. ls Python:
os.system('ls > /tmp/lsoutput')
print open('/tmp/lsoutput', 'r').read()
- . python ( python getoutput() )
import subprocess
process = subprocess.Popen(['ls', '-a'], stdout=subprocess.PIPE)
out, err = process.communicate()
print(out)
- , . , Python
import os
for filename in os.listdir('.'):
print filename