September 28th, 2006, 02:02 AM
Script to automate CLI applications
Is it possible to pass commands to a running dos program using external batch file or using perl or some kind of language in windows?
My problem is that I'm trying to write some scripts that will automatically launch other applications and send commands to these applications after they are launched. All the applications I'm dealing with are command line interfaced. Can this be done? Is it possible is what I'm really asking, and if so, what language or what libraries are needed?
Help is very much appreciated, cuz I'm sooooo desparate! I've been trying to work around the problem by trying to find only command line programs that accept instructions either by a file or all in the one argument used to launch the application and it's not easy! I basically got stuck when I hit Jabber. I tried some of the perl scripts available online, but one script requires another dependency and another requires another and so. I guess it's cuz I'm dealing with Windows and not unix that's why so many dependencies.
Anyone any thoughts?
September 28th, 2006, 02:30 AM
If you only need to feed it a fixed sequence of commands then you could try redirecting stdin from a file using the '<' operator, e.g.
If you need to interact with the program, e.g. send different commands depending on what it prints, then it is much more difficult. There is a program in UNIX-land called "expect" that does this, so you could try googling for a windows version, but I don't know of any. I dont think Windows gives you the sort of low-level access to the console that UNIX does, so such a program would be hard to write.
Alternatively there are several programs that let you control a GUI through a script, so if your program has a GUI interface as well you could try that. One such program is AutoIt, but I have seen others.
September 28th, 2006, 02:37 AM
After a little googling, I see that ActiveTCL from ActiveState includes a Windows version of Expect.
TCL is a simple scripting language that is used to drive Expect. It is not hard to learn and there are plenty of books and online resources for it.
September 28th, 2006, 06:48 AM
The easiest way would be to write it in perl or python and open a pipe to the command through which you can feed it data and receive it back.
perl python pexpect
There's also the os.popen function you can look up in the python docs and cpan expect modules (you may like Expect::Simple)
September 28th, 2006, 05:08 PM
Thanks for all your suggestions. ActiveTCL "tickle" haha funny name, is pretty useful, but sadly most of the functions are not implemented on windows yet. The redirection symbol " < " is pretty handy too, but doesn't always work for all programs. I think I'll find a way around the Jabber client and maybe find some easy to use Jabber bot source code.