#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    22
    Rep Power
    0

    Script to automate CLI applications


    Hi,

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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.

    somcommand.exe <instructions.txt

    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.

    Dave
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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.

    Dave
  6. #4
  7. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1050
    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)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    22
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo