Automatically filling in answers to interactive shell command questions
Jp Calderone
exarkun at intarweb.us
Mon Jul 21 19:27:32 EDT 2003
On Mon, Jul 21, 2003 at 03:23:25PM -0700, Ted Weatherly wrote:
> Is it possible to use python to automatically fill in the answers to
> interactive shell command questions? For example, I am using a shell
> command addperson that behaves as follows:
>
> > addperson
> First Name: Ted
> Birthday: 12/08/1977
> Height: 6'0"
> Location: San Francisco, CA
> >
>
> I am prompted for "First Name: " and I enter "Ted". I am prompted for
> "Birthday: " and I enter "12/08/1977". Imagine doing this for 100
> people or more...it gets tiresome.
>
> Assuming I can't change the addperson command to read data from a
> file, is there any way to use python to fill in the data for the
> expected questions? Perhaps a different language would be better?
>
Ahh, but addperson already reads data from a file! stdin! Have you
tried:
cat answer_file | addperson
or even
addperson < answer_file
or, to keep it Python related,
>>> import os
>>> outf = os.popen('addperson', 'w')
>>> inf = file('answer_file', 'r')
>>> outf.write(inf.read())
>>> inf.close()
>>> outf.close()
Jp
--
"If you find a neighbor in need, you're responsible for serving that
neighbor in need, you're responsible for loving a neighbor just like you'd
like to love yourself." -- George W. Bush, Sept. 16, 2002
More information about the Python-list
mailing list