Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > Automatize an interactive program, how???

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 06-30-2009   #1 (permalink)
Just Joined!
 
Join Date: Apr 2009
Posts: 2
Question Automatize an interactive program, how???

Hi there!
I need to run an easy program consisting in 4 file executions in a row. But in between, the user has to type 'enter' or '1' a number of times, always the same.

My question: in the following script:
#!/bin/bash
vors
rnd
smor3D
bintoc

I need to input 'Enter' while some of the programs run; plus to stop the third one (smor3D) when it's result file has certain size (let's say >0; would suffice by now).

So, it's this program that's brought me to Linux, & it's great, but I have no clue on how to do this & have an approaching deathline to submit results. I need to automatize this program run (so to install it in a few computers & let them work for a week, or two).

Any help will be greatly, madly appreciated!!!! I'll keep doing my own research meanwhile.
Cheers!!!
calexica is offline  


Reply With Quote
Old 06-30-2009   #2 (permalink)
Just Joined!
 
tetsujin's Avatar
 
Join Date: Oct 2008
Posts: 66
Quote:
Originally Posted by calexica View Post
Hi there!
I need to run an easy program consisting in 4 file executions in a row. But in between, the user has to type 'enter' or '1' a number of times, always the same.

My question: in the following script:
#!/bin/bash
vors
rnd
smor3D
bintoc

I need to input 'Enter' while some of the programs run; plus to stop the third one (smor3D) when it's result file has certain size (let's say >0; would suffice by now).
OK, first off, I assume these are text-mode (TTY) programs, and not windowed applications?

Basically there are two ways a TTY program can take user keyboard input: the first is via "standard input", the second is by accessing the process's controlling TTY directly.

Ordinarily these two approaches yield the exact same result: but if you redirect a program's input, then stdin for that program will not be the program's TTY but rather whatever you've redirected stdin to be... For instance:

Code:
mkdir test; cd test
touch a b c d e f g
chmod a-w *
# The files are now not writable: attempts to remove them using "rm" without the "force" flag will result in a user prompt, if "rm" is in interactive mode...  "rm" is normally in interactive mode only if stdin is a TTY - so here we force it interactive with --interactive...
(while true; do echo y; done) | rm --interactive *
# All the "are you sure?" prompts from interactive mode were answered "yes" by the pipeline input...
Now, that kind of pipelining input works only if the program takes its input from stdin. If it goes directly to the TTY (by opening /dev/tty, etc.) then it effectively bypasses this mechanism. Certain programs will do this when printing password prompts, for instance, to discourage users from putting passwords into shell scripts. If you need to provide input to a program that takes input from its TTY, then you need to either run the program in such a way that its controlling TTY is a pseudo-TTY, and then write the data in on the PTY master, or else you need to use an ioctl to push data into the TTY's input buffer...

Either method is a bit more complicated to explain fully - but the point I want to get across mostly is just that if the program uses TTY input, then the normal shell redirects won't affect it. You could use a program like "expect" to interact with the program in this case...

If it is a GUI app, then the way it interfaces with the keyboard is totally different - I don't know the answer in that case.
tetsujin is offline   Reply With Quote
Old 07-01-2009   #3 (permalink)
Just Joined!
 
Join Date: Apr 2009
Posts: 2
Hey!!!!!!!! thanks so, so much! it was so terribly easy!!

#!/bin/bash
vors < inputEnter
rnd < inputEnter
smor3D
bintoc < inputEnter

Being the content of inputEnter = ^M

hahahahahahahaha!!!!!!!!!!!!!!!!!!! not yet finished with the second part (to stop the third one (smor3D) when it's result file has certain size (let's say >0; would suffice by now), but no worries now.

'stdin' was the keyword.
calexica is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 01:29 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2