Input Redirection


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Input Redirection
# 1  
Old 07-08-2002
Question Input Redirection

Hi everybody, first of all i am a new member in UNIX.com and this is my first post.
I am impressed with the amount of information a person can ever have in this forum, it is really great having something similiar; anyways let me tell you about the problem I am having, hope you will answer me. (P.S: I am new to UNIX, it's been only couple of months I started working on a UNIX machine, so please be patient on me )

I am trying to redirect the input of a executable from a file, i've wrote the required input in that file, but for some reasons the executable isn't taking them in the right order, it is like if it's missing something, and at the end, when the file finish before the input requirement of the program, it start a loop of a character which looks like ~ this one or sometimes .f.
the input required is :
T
[return]
2
1
[return]
q
q

I am putting that in a file let's say called test
and starting the command as follows :
#command < test

am I missing anything ??
# 2  
Old 07-08-2002
There is not enough information here to be sure, but here is my guess... Not all programs can respond to input redirection. A prime example is the passwd program. But it ignores its standard input and opens /dev/tty. Perhaps this program does a combination or reading from standard input and reading from /dev/tty. Or more likely, it puts the tty into raw mode and is not prepared for the different semantics that arise from reading a file. But one way or another, your program seems to require tty input.

The standard solution in such a case is to get the public domain program, "expect". If you search our site on "expect" you find lots of threads answering questions about it.

And, by the way, welcome to the site!
# 3  
Old 07-08-2002
Thanks Perderabo for your reply, what I am sure about is that i have no clue about what you mean by saying your program seems to require tty input and how that would make a difference, trying to give more information:
the program is a third party application running on AIX, tcsh, it ask user interactively for the options he may need to check.

Anyways, I will search for expect now. hope to find what i need :-)
thanks again.
# 4  
Old 07-08-2002
Quote:
Originally posted by majeed73
Thanks Perderabo for your reply, what I am sure about is that i have no clue about what you mean by saying your program seems to require tty input and how that would make a difference,
There are many ways that a program can set itself up to work with a tty but fail with file input. They are rather complex. But I will describe one of them.

By sending the correct ioctl()'s calls to the standard input (which is assumed to be a tty), the program can set the MIN > 0 and the TIME > 0. (exactly how to do this is documented under "man termio") Once that is done, the program can then issue a multi-char read system call. The editor vi works this way and you can't redirect your input into it either.

If The MIN is 1, then a read() will not return until at least one character has been typed. But if TIME is also 1, after a character arrives, the tty driver will wait up to one tenth of a second to see if another character arrives. If it does, a read() of 10 characters would get both characters returned to it. If it didn't, the read() would get just the one character. This is how a program can read a single keystroke. The "A" key will just send the character "A". But the home key will send a mult-character sequence. The program wants to read keystrokes, not characters.

But now redirect a file into our program. First the ioctl()'s will now fail. But some programs just ignore the error. Next the multi-byte read() occurs and it gets as many bytes as it specified. In your example you have the characters:
2
1
But there is an implied delay between those keystrokes. The program was depending on that delay. So it gets "21" when it just wanted "2".

This is just one way to depend on a tty for input. Read the "man termio" to see everything that the tty driver can offer to the program.
# 5  
Old 07-08-2002
your being really very helpful Perderabo, I just remembered one behavior of the program I am running
when it run interactively.
the program expect [return] after the first input ("T" in our case)
then it ask for (do you want to run in recovery mode [y/n] ) default is no, and [return] is enaugh, after that it doesn't wait for the [return] key after the keystroke, as soon as you press "2" it will go to the corresponding submenu and so on.....

I hope i was clear in what i am trying to say.
# 6  
Old 07-08-2002
For a program to respond to a single keystroke like that it must be using ioctl()'s to the tty driver. That is a good indication that you will have trouble if don't use a tty.
# 7  
Old 07-08-2002
Thanks

well i think i have to try using "expect". I have to wait till tomorrow to go to the office :-)

Thanks for your great help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input redirection within bash script

Hi, when I try to redirect input and the command is described as a string within an array redirection does not work. why? #!/bin/bash dir=("tail < ./hello.txt") tail < ./hello.txt #works ${dir} #does not work (2 Replies)
Discussion started by: heinzel
2 Replies

2. Shell Programming and Scripting

Input redirection script

Hi, #!/bin/bash while ; do rm -f /tmp/pipe mkfifo /tmp/pipe ./yuv4mpeg_to_v4l2 < /tmp/pipe & mplayer tom_and_jerry.mp4 -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe sleep 65; done When I run this - after mplayer finishes playing video it says - Exiting... (End of... (2 Replies)
Discussion started by: ashokvpp
2 Replies

3. UNIX for Dummies Questions & Answers

When do I use input redirection?

Can someone please explain when input redirection is necessary? For example, "cat filename" and "cat< filename" produce the same result. I was told that if I need to bunzip a file that I should type "bunzip2<filename.bz2." However, if I omit the "<" I still get the same result. Can someone... (4 Replies)
Discussion started by: PTcharger
4 Replies

4. UNIX for Dummies Questions & Answers

Redirection of file input to command

Hello, I'm new to Unix (working with OS X 10.8.5) and therefore at the beginning of my adventure. If I ask something stupid, then this is not intentional, but simple nescience. :rolleyes: I have a problem with the redirection of text file content to echo. I was experimenting with redirection... (6 Replies)
Discussion started by: pseudo
6 Replies

5. UNIX for Dummies Questions & Answers

Send job to Background after input redirection

Hi, I am having issues with syntax when I am trying to send a job to the background after a input redirection. I have this script which sends some files to different servers after zipping them. Once I execute it, it will ask for user input as of which server the files need to go to. (The... (3 Replies)
Discussion started by: grep_me
3 Replies

6. Shell Programming and Scripting

How to check for Input Redirection in my script?

All, I have a requirement to write a script where I check for Input redirection when the script was executed, based on which I handle my logic. Below is the example: my.script #! /bin/ksh # Not sure how to frame the if condition below if ; then echo "Input Redirected from a file" ... (7 Replies)
Discussion started by: bharath.gct
7 Replies

7. Shell Programming and Scripting

Input redirection and for loop

Hello, I need help with a bash script that I try to improve. I could not find answer so far, maybe because I'm not to familiar with the terminology so feel free to correct my language. I have a script that looks like: NODES="node_a node_b node_c" for NODE in $NODES do ... (4 Replies)
Discussion started by: pn8830
4 Replies

8. UNIX for Advanced & Expert Users

password required when using input redirection

Hello, I need to change user and run some commands by using a script. lets say, I'm using su - someuser << start password required -----> how can I enter the password here command 1 command 2 command 3 command 4 start While trying to run this I got the following message: "standard... (2 Replies)
Discussion started by: Alalush
2 Replies

9. Shell Programming and Scripting

permanent redirection of standard input

while running a user inter-active program how can we get the commands from a file instead of the user? is there anyway to permanently redirect content of a file to standard input? (6 Replies)
Discussion started by: gfhgfnhhn
6 Replies

10. Shell Programming and Scripting

input redirection question

Hi, in my script I need to execute the following command: query $id 456 432 but it waits for a RETURN character from keyboard and therefore, it fails. I tried something like: query $id 456 432 << '\n' but, i'ts clear it is not correct. Is there any way to do this? Thxs. (0 Replies)
Discussion started by: luistid
0 Replies
Login or Register to Ask a Question