python - Program output that is neither STDOUT or STDERR? -
i'm getting strange behavior when trying capture output of django's manager.py
> ./manage.py runserver 0.0.0.0:2869 validating models... 0 errors found django version 1.3.1, using settings 'polling.settings' development server running @ http://0.0.0.0:2869/ quit server control-c. error: port in use. > ./manage.py runserver 0.0.0.0:2869 >stdout 2>stderr > cat stderr error: port in use. > cat stdout >
why getting empty string when try capture output on second run?
any program detect if stdout and/or stderr connected terminal or not: man isatty(3). python has such functionality: sys.stdout.isatty().
probably python script or logging subsystem prints lines missing in second run when running on terminal i.e. in interactive mode. it's common , proper practice. example, there no sense print "quit server control-c"
if output redirected log file.
below simple illustration:
#!/usr/bin/python import sys print "print always." if sys.stdout.isatty(): print "print on tty!"
here go:
$ ./test.py print always. print on tty! $ ./test.py > log $ cat log print always. $
Comments
Post a Comment