Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old September 28th, 2006, 01:02 AM
lax lax is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 22 lax User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 25 m 17 sec
Reputation 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?

Reply With Quote
  #2  
Old September 28th, 2006, 01:30 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,188 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 11 h 25 m 43 sec
Reputation Power: 251
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

Reply With Quote
  #3  
Old September 28th, 2006, 01:37 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,188 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 11 h 25 m 43 sec
Reputation Power: 251
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

Reply With Quote
  #4  
Old September 28th, 2006, 05:48 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 23 m 58 sec
Reputation Power: 1008
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)

Reply With Quote
  #5  
Old September 28th, 2006, 04:08 PM
lax lax is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 22 lax User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 25 m 17 sec
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Script to automate CLI applications


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway