ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I am trying to write a linux script that would launch a program then the program itself has its own command prompt. Once the program starts I need to issue some commands in the program's prompt to get the program running.
My main question is, is it possible to write a script that will start the program, then input specific commands for that program?
I need to do this repeatedly, start program, load data set, run many commands then quit, restart program then load new dataset and so on. A real pain and very time consuming.
it's possible. When your new program starts up it will connect itself to an input device in /dev (probably something like /dev/ttyS2) etc. You're script can then open that device and begin writing to it like a file.
however, are you sure that the app your starting cannot recieve stuff through piping? (this would be way easier).
ie ... when I execute 'ls | grep jason | less' the system automatically feeds the output of 'ls' into 'grep' and feeds the output of 'grep' into 'less'.
not a problem ... and if you are unfamiliar with piping you may find it very useful to find a 'bash scripting' howto out there ... there are MANY very handy tools available to you that can probably help you in many other areas as well.
most how-tos can be found at The Linux Documentation Project (www.tldp.org)
If you can not do this using pipes, as jpbarto suggested, because the program is interactive, then there's the "expect" utility. With this you can program input for interactive programs.
See "man expect" from more info.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.