LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-24-2010, 02:33 PM   #1
Euler2
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, 02:44 PM   #2
rweaver
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:

Code:
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 02:47 PM.
 
Old 02-24-2010, 04:12 PM   #3
smeezekitty
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, 09:44 PM   #4
Euler2
LQ Newbie
 
Registered: Oct 2009
Posts: 20

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

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

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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, 10:53 AM   #6
rweaver
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 10:54 AM.
 
  


Reply



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 04:06 PM
Bash script: Dealing with program input from a pipe sleeper0110 Linux - Software 5 04-28-2009 03:41 PM
Automating tasks by redirecting input lsgko Linux - Software 4 02-26-2006 11:47 PM
Bash Shellscript automating command input JoeneB Programming 3 01-13-2006 01:59 AM
C++ Newbie stuck on first simple program webwolf70 Programming 8 09-14-2004 01:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:26 PM.

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