The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 04:52 AM
Asking about shell script input output redirection trivektor Shell Programming and Scripting 1 10-18-2006 01:13 AM
input redirection question luistid Shell Programming and Scripting 0 08-22-2006 07:28 AM
How to prompt for input & accept input in ONE line newbie168 Shell Programming and Scripting 2 09-27-2005 05:02 AM
Changing stdin from file redirection to console input nauman High Level Programming 4 09-29-2001 08:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-08-2002
majeed73 majeed73 is offline
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 ??
  #2 (permalink)  
Old 07-08-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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
majeed73 majeed73 is offline
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
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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
majeed73 majeed73 is offline
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
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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
majeed73 majeed73 is offline
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0