The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
permanent redirection of standard input gfhgfnhhn Shell Programming and Scripting 6 11-01-2006 12:52 AM
Asking about shell script input output redirection trivektor Shell Programming and Scripting 1 10-17-2006 10:13 PM
input redirection question luistid Shell Programming and Scripting 0 08-22-2006 04:28 AM
How to prompt for input & accept input in ONE line newbie168 Shell Programming and Scripting 2 09-27-2005 02:02 AM
Changing stdin from file redirection to console input nauman High Level Programming 4 09-29-2001 05:42 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2002
Registered User
 

Join Date: Jul 2002
Location: Dubai - UAE
Posts: 5
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 ??
Forum Sponsor
  #2 (permalink)  
Old 07-08-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,355
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 (permalink)  
Old 07-08-2002
Registered User
 

Join Date: Jul 2002
Location: Dubai - UAE
Posts: 5
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 (permalink)  
Old 07-08-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,355
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 (permalink)  
Old 07-08-2002
Registered User
 

Join Date: Jul 2002
Location: Dubai - UAE
Posts: 5
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 (permalink)  
Old 07-08-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,355
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 (permalink)  
Old 07-08-2002
Registered User
 

Join Date: Jul 2002
Location: Dubai - UAE
Posts: 5
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.
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0