Mysterious EOFError

Rex Eastbourne rex.eastbourne at gmail.com
Sun Apr 9 15:29:25 EDT 2006


Thanks. Do you know of a solution to this? I tried the following, which
I found on this newsgroup:

#============

lines = open(sys.argv[1]).readlines()

#============

sys.stdin = open('/dev/tty')
a = raw_input('Prompt: ')

#============

sys.stdin = os.fdopen(3)
a = raw_input('Prompt: ')

#============

What I want to do is execute a scheduled task that prompts me for
something and allows me to enter it and have it stored somewhere. I'm
on Ubuntu Linux.

Thanks in advance!

Steven D'Aprano wrote:
> On Sat, 08 Apr 2006 23:07:54 -0700, Rex Eastbourne wrote:
>
> > Hi,
> >
> > I'm executing a python script as a cron job. When I run it myself from
> > the command line it works, but when cron executes it I get an EOFError:
> >
> > File "/home/rex/cronscript.py", line 6, in ?
> >     level = int(raw_input("hello?"))
> > EOFError: EOF when reading a line
>
>
> Because raw_input is waiting for input from the user. I assume that when
> cron runs a Python script, and there is no actual human user to enter a
> string in response to raw_input, it raises a EOF error.
>
> Written in the docs:
>
> http://docs.python.org/lib/module-exceptions.html
>
>
> exception EOFError
>     Raised when one of the built-in functions (input() or raw_input())
>     hits an end-of-file condition (EOF) without reading any data. (N.B.:
>     the read() and readline() methods of file objects return an empty
>     string when they hit EOF.)
> 
> 
> -- 
> Steven.




More information about the Python-list mailing list