views:

135

answers:

3

I needed to have a directly executable python script, so i started the file with "#!/usr/bin/env python". However, i also need unbuffered output, so i tried "#!/usr/bin/env python -u", but that doesn't work. ("python -u: no such file or directory")

I found out that "#/usr/bin/python -u" works, but it doesn't suit my needs because i need it to get the python in PATH to support virtualenv envoriments.

What are my options?

+1  A: 

Passing arguments to the shebang line is not standard and in as you have experimented do not work in combination with env in Linux. The solution with bash is to use the builtin command "set" to set the required options. I think you can do the same to set unbuffered output of stdin with a python command.

my2c

neuro
A: 

This is a kludge and requires bash, but it works:

#!/bin/bash

python -u <(cat <<"EOF"
# Your script here
print "Hello world"
EOF
)
imgx64
+1  A: 

You could have a look at this SO question for a bit of info about how to do unbuffered output.

Mattias Nilsson