From: askaholik on
Hi all,

I have a program that requires interactive inputs and I want to
somehow pass my inputs automatically to it.

To be more clear, it looks like that
$./oldProgram
write a name: [the program is waiting for some input, I type "hello"
and press enter]
write the surname: [the program is waiting for some input, I type
"foo" and press enter]
etc...

I want to avoid passing the values from standard input (I have to call
that program hundreds times), I remember there was a trick to do it,
but I cannot figure it out. Any hint would be appreciated!!!

cheers,
Askaholik
From: Janis Papanagnou on
askaholik schrieb:
> Hi all,
>
> I have a program that requires interactive inputs and I want to
> somehow pass my inputs automatically to it.
>
> To be more clear, it looks like that
> $./oldProgram
> write a name: [the program is waiting for some input, I type "hello"
> and press enter]
> write the surname: [the program is waiting for some input, I type
> "foo" and press enter]
> etc...

For example...

../oldProgram << EOT
hello
foo
EOT

or...

echo $'hello\nfoo' | ./oldProgram


Janis

>
> I want to avoid passing the values from standard input (I have to call
> that program hundreds times), I remember there was a trick to do it,
> but I cannot figure it out. Any hint would be appreciated!!!
>
> cheers,
> Askaholik
From: askaholik on
On Aug 5, 2:16 am, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:

> echo $'hello\nfoo' | ./oldProgram

thank you very much Janis, it is exactly what I was looking for!!!!!!
From: blmblm on
In article <i3c3o1$hqp$1(a)speranza.aioe.org>,
Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
> askaholik schrieb:
> > Hi all,
> >
> > I have a program that requires interactive inputs and I want to
> > somehow pass my inputs automatically to it.
> >
> > To be more clear, it looks like that
> > $./oldProgram
> > write a name: [the program is waiting for some input, I type "hello"
> > and press enter]
> > write the surname: [the program is waiting for some input, I type
> > "foo" and press enter]
> > etc...
>
> For example...
>
> ./oldProgram << EOT
> hello
> foo
> EOT
>
> or...
>
> echo $'hello\nfoo' | ./oldProgram
>
>
> Janis
>
> >
> > I want to avoid passing the values from standard input (I have to call
> > that program hundreds times), I remember there was a trick to do it,
> > but I cannot figure it out. Any hint would be appreciated!!!

To the OP, and for future reference, maybe:

Janis's solutions do *not* avoid the use of standard input, as
the term is used in context. What they do is "redirect" this
input stream, so it comes from something other than the keyboard.
Some programs actually do read directly from the keyboard [1],
and this kind of redirection won't work with them, but I think
I'm safe in saying [2] that most traditional-UNIX programs read
from standard input, and they do so in part because redirection
is so useful!

[1] "expect" supposedly provides a way to automate input to such
programs, but I haven't worked with it myself.

[2] And if I'm not, someone will be along soon to explain why not.
Sort of a :-).

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
From: WANG Cong on
On 08/04/10 20:33, blmblm(a)myrealbox.com <blmblm(a)myrealbox.com> wrote:

> In article <i3c3o1$hqp$1(a)speranza.aioe.org>,
> Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
>> askaholik schrieb:
>> > Hi all,
>> >
>> > I have a program that requires interactive inputs and I want to
>> > somehow pass my inputs automatically to it.
>> >
>> > To be more clear, it looks like that
>> > $./oldProgram
>> > write a name: [the program is waiting for some input, I type "hello"
>> > and press enter]
>> > write the surname: [the program is waiting for some input, I type
>> > "foo" and press enter]
>> > etc...
>>
>> For example...
>>
>> ./oldProgram << EOT
>> hello
>> foo
>> EOT
>>
>> or...
>>
>> echo $'hello\nfoo' | ./oldProgram
>>
>>
>> Janis
>>
>> >
>> > I want to avoid passing the values from standard input (I have to call
>> > that program hundreds times), I remember there was a trick to do it,
>> > but I cannot figure it out. Any hint would be appreciated!!!
>
> To the OP, and for future reference, maybe:
>
> Janis's solutions do *not* avoid the use of standard input, as
> the term is used in context. What they do is "redirect" this
> input stream, so it comes from something other than the keyboard.
> Some programs actually do read directly from the keyboard [1],
> and this kind of redirection won't work with them, but I think
> I'm safe in saying [2] that most traditional-UNIX programs read
> from standard input, and they do so in part because redirection
> is so useful!
>

I think that is not safe, there are a considerable amount of
Unix programs which don't work with Janis' solution, especially when
dealing with passwords, for example, passwd, su, rlogin etc..
expect(1) always work, and it is not hard to write a simple expect
script to solve OP's problem.


--
Live like a child, think like the god.