in a script I use sys.stdout.write() to output processed data to stdout, which later I use on CLI to redirect stdout to file:
python.exe script.py > file.out
I could not write to file inside python script as redirected file can’t be known
My problem is that I use also raw_input(), as I need user to pass certain number before processing starts, but prompt doesn’t show as I redirect stdout – i.e. script waits for user input but does not show anything
Can someone give me a tip how to handle this?
TIA
Take the filename as a command-line argument instead of redirecting stdout. That way, you can print output or use
raw_input()as normal. Example:Usage:
This will work on any platform.