[Ilugc] raw_input and stderr redirection in python
Noorul Islam K M
noorul at noorul.com
Fri Feb 10 10:06:56 IST 2012
Shrinivasan T <tshrinivasan at gmail.com> writes:
> Friends.
>
> It seems there are some issues with python raw_input and redirecting
> stderr in bash
>
> Here is the code:
>
> File: test.py
>
> print "Test Program"
> name=raw_input("Enter Your name: ")
> print name
>
> Execution:
> <snip>
>
> $python test.py
> Test Program
> Enter Your name: shrini
> shrini
>
>
> $python test.py 2> error
> Test Program
>
Did you see the content of the error file. It looks like raw_input() is
sending the prompt string to stderr. But still it waits for the user
input.
So may be one of the solutions could be
import sys
print "Test Program"
sys.stdout.write('Enter Your name: ')
name = raw_input()
print name
Thanks and Regards
Noorul
>
> </snip>
>
> When use redirections while calling python program, the raw_input is
> not working.
>
> There is some interesting dicsussion here:
> http://bytes.com/topic/python/answers/27498-raw_input-why-doesnt-prompt-go-stderr
>
> Is there any way to use both raw_input and error redirection?
More information about the ilugc
mailing list