script to write to standard input ?

  • Follow


hi all,

I have a script that I want to send some standard input to (eg simulate
the user typing 'a' - ENTER ). If I try echo a | myscript, I receive an
error: option:stty: : Not a typewriter

This is running in ksh.

Help!

TIA

eddiec :-)

0
Reply chalk (34) 12/20/2005 12:31:02 AM

"pc" <chalk@netspace.net.au> writes:

> hi all,
>
> I have a script that I want to send some standard input to (eg simulate
> the user typing 'a' - ENTER ). If I try echo a | myscript, I receive an
> error: option:stty: : Not a typewriter
>
> This is running in ksh.

This depends on your script.  For example:

Given x.sh:

#!/bin/ksh
read ans
echo "answer is $ans"

I get:

echo "aa" | ./x.ksh
answer is aa

Maybe the script shouldn't be fooling with the stty command.
0
Reply daneNO (319) 12/20/2005 1:18:37 AM


On Tue, 20 Dec 2005 02:18:37 +0100, Dan Espen <daneNO@SPAM.mk.telcordia.com> wrote:

> "pc" <chalk@netspace.net.au> writes:
>
>> hi all,
>>
>> I have a script that I want to send some standard input to (eg simulate
>> the user typing 'a' - ENTER ). If I try echo a | myscript, I receive an
>> error: option:stty: : Not a typewriter
>>
>> This is running in ksh.
>
> This depends on your script.  For example:
>
> Given x.sh:
>
> #!/bin/ksh
> read ans
> echo "answer is $ans"
>
> I get:
>
> echo "aa" | ./x.ksh
> answer is aa
>
> Maybe the script shouldn't be fooling with the stty command.

Given that the script is fooling with the stty command, if the OP
cannot change that, he need to use pseudo-terminal (pty).

To the OP:

I don't remember all the incantations required off the top of my
hat, but as a basis for futher googling/man-pageing:

The left-hand-side script (the one doing "echo") opens a "master pty"
- nowadays, you open /dev/ptmx, every open of this one produces a new
pty. A pty has two sides, the master and the slave. The slave is created
in /dev/pts, e.g. /dev/pts/3.

The right-hand side of your pipe opens the slave. That means there is
not formally a pipe, your code must first create the pty, then
you do .x.ksh < /dev/pts/$n with the right $n.

To find out which of the files in /dev/pts is the new one, you must do
a system call... Yes, man ptmx says you must run three system calls
before you can allow the right hand side open the slave.  That pretty
much means you must do a little C programming to do this.

-Enrique
0
Reply enrio (209) 12/20/2005 4:12:20 AM

pc <chalk@netspace.net.au> wrote:
> I have a script that I want to send some standard input to (eg simulate
> the user typing 'a' - ENTER ). If I try echo a | myscript, I receive an
> error: option:stty: : Not a typewriter

Alter the way you take input in the script. You appear to be using sme
method that wants a terminal.

> Help!

What about? You'll have to be precise about the problem. State the
command you are using.

Peter
0
Reply ptb (2756) 12/20/2005 8:33:05 AM

On Mon, 19 Dec 2005 23:12:20 -0500, Enrique Perez-Terron <enrio@online.no> wrote:

> On Tue, 20 Dec 2005 02:18:37 +0100, Dan Espen <daneNO@SPAM.mk.telcordia.com> wrote:
>
>> "pc" <chalk@netspace.net.au> writes:
>>
>>> hi all,
>>>
>>> I have a script that I want to send some standard input to (eg simulate
>>> the user typing 'a' - ENTER ). If I try echo a | myscript, I receive an
>>> error: option:stty: : Not a typewriter
>>>
>>> This is running in ksh.
>>
>> This depends on your script.  For example:
>>
>> Given x.sh:
>>
>> #!/bin/ksh
>> read ans
>> echo "answer is $ans"
>>
>> I get:
>>
>> echo "aa" | ./x.ksh
>> answer is aa
>>
>> Maybe the script shouldn't be fooling with the stty command.
>
> Given that the script is fooling with the stty command, if the OP
> cannot change that, he need to use pseudo-terminal (pty).

As long as the script doesn't exit on error the OP can probably
ignore that error and the script will likely behave as expected.
It's probably trying to turn off echo or some such.
0
Reply joe248 (217) 12/20/2005 6:51:29 PM

4 Replies
48 Views

(page loaded in 1.503 seconds)

Similiar Articles:













7/28/2012 7:39:14 AM


Reply: