Automating Input to a program with a simple script--Help I'm stuck
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
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.
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/ < <(
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.