Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-24-2010, 03:33 PM   #1
LQ Newbie
Registered: Oct 2009
Posts: 20

Rep: Reputation: 0
Automating Input to a program with a simple script--Help I'm stuck

I know this should be pretty easy, but for the life of me I can't quite get it to work.

I have a program (lets call it trjconv) calling it from the command line has the following structure

trjconv -f (file one) -s (file 2) -o (output)

Once it loads it requires me to enter a selection, which is always "1".

I need to run this command roughly 500 times, and it is an absolute pain to have the computer on my lap the whole time just so I can press 1 and enter every 45 seconds.

At this point I'll use just about anything to automate this process (though I prefer awk or sed since I am working on learning them).

Thank you for any and all help.
Old 02-24-2010, 03:44 PM   #2
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
It depends a bit on the program in question and if it correctly handles piped input, but try this:

yes 1 | trjconv -f (file one) -s (file 2) -o (output)
This really isn't an optimal job for awk or sed, if the simple answer above doesn't work i would suggest trying expect, it is built for exactly that kind of automation. You could also look at autoexpect, but this would be a pretty trivial expect script.

Last edited by rweaver; 02-24-2010 at 03:47 PM.
Old 02-24-2010, 05:12 PM   #3
Senior Member
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
how about echo 1 | trjconf ...
Old 02-24-2010, 10:44 PM   #4
LQ Newbie
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Echo worked. Thanks.

-Problem Solved-
Old 02-24-2010, 11:05 PM   #5
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
You can also add ` < <(yes 1)' to the end of the command.

I use this for commands like cp and mv with "interactive" options.
If you want to answer "no" since a non-zero replay is the same, you can get colorful and put a smiley in your command:
mv -vi source/* dest/ < <(
Old 02-25-2010, 11:53 AM   #6
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
If echo worked then yes should work, the only issue I see with using echo is it's only going to execute one time and then it will sit there forever, although in retrospect I may have misread your issue. If you need multiple 1's inputed use yes, if you need a single 1 inputed use echo. If you're running the same command 500 times you might want to put it in a loop and do the echo/yes as appropriate.

Last edited by rweaver; 02-25-2010 at 11:54 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple C Program, but stuck - please help hubabuba Programming 4 06-13-2009 05:06 PM
Bash script: Dealing with program input from a pipe sleeper0110 Linux - Software 5 04-28-2009 04:41 PM
Automating tasks by redirecting input lsgko Linux - Software 4 02-27-2006 12:47 AM
Bash Shellscript automating command input JoeneB Programming 3 01-13-2006 02:59 AM
C++ Newbie stuck on first simple program webwolf70 Programming 8 09-14-2004 02:29 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration