Skip to content

anilchander1/WindowsConsoleAutomator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WindowsConsoleAutomator

Automate Interactive Win32 Console Programs

#Why? Because i did not find any portable low footprint utility to automate the windows console based programs , especially interactive programs.Python based modules like wexpect had dependencies and was not easily portable for my needs.Also such modules need python familiarity.

#How to build? Open the project in Visual Studio 2012 or later and build.You will get <200 KB file, integrated.exe.If lazy, download the binary from here: https://drive.google.com/file/d/0B-4scr3fQpEcRlBDSTNLU252UzA/view?usp=sharing

#usage Make sure that you have the latest Microsoft VC++ redistributable is installed. integrated.exe linux.ini
where "integrated.exe" is the name of the executable and ini file is the file to control the intented program.The execuatble file will read the ini file contents into memory.Then it will set any working directory specified for the session,set the environment variables for the session and start running the program specified with arguments ,if any.How the program needs to be terminated is specified by END keyword.

#Sections of ini file


[Path]
Under this section you can set the working directory using "key=value" style specification.Key can be any unique string.The log files for the current session will be created in the specified directory.
Example: PATH1=C:\MYDIRECTORY

[EnvironmentVariables]
Under this section specify all the environment variables those need to be set.All of them should be in a "key=value" format, where key is the environment variable and value is its value.
Example: JAVA_HOME=C:\JDK1.5


[ProgramSection]
Under this section specify the program name to be run and arguments for the program .All of them should be in a "key=value" format, where key "ProgramName" is for the program to be run and key "Arguments" is for the program's arguments.These keys should not be changed.For key "ProgramName" value is mandatory & should be an absolute path to the program,however for key "Arguments" value can be blank(but just keep the key there).
Example: ProgramName=C:\mydirectory\mypgm.exe
Arguments=/F /D

***You can nest program call inside another program like :
ProgramName=cmd
Arguments=C:\mydirectory\mypgm.exe /F /D


[SequenceCommands]
This section specifies how the program to be controlled at run time by emulating a virtual user.

These are some sequence of steps specifed in keyvalue pair ,ending with the last step having key "END".

Key should be unique and it also serves as description of that step.The value can have a mximum of 5 parameters seperated by pipe delimiter.

Parameters are:

  1. An expected value at the current prompt.The current prompt(where the current cursor position is) will be matched against this value.If you suffix the key with '#' then this value will be checked in last commands execution result(The whole buffer string just before the line of current cursor position).In both cases the values can be regularexpressions.mandatory
  2. A command to be executed when parameter 1 is matched.If "{ENTER}" is given as a value,it just simulates hitting return/enter key.A blank or space will type a space and then enter/return will be hit.mandatory
  3. Key of the next step to be executed when parameter 1 is matched & param 2 is executed.not mandatory, if the next two parameters are not given.In this case the next step in sequence will be executed
  4. Key of the next step to be executed when parameter 1 is not matched.not mandatory, if the next parameter is not given.In this case the next step will be the step with key "END"
  5. Maximum timeout in seconds.The current prompt will be checked in every 1-2 seconds until the timeout is reached.not mandatory.In this case 25 seconds will be the default timeout

Any line starting with ';' anywhere in ini file will be treated as a comment.
The END step needs only a single value: "which ever command to be executed to exit the program"

Example:

[SequenceCommands]
login=.*login.*|user1|password|END
password=.*password.*|passwd|prompt|END
;execute somecommand when prompt contains username
prompt=.*user1.*>|somecommand|ls#|END|3
;check the result of somecommand execution contains "hist" and go to end.
ls#=.*hist.*|END
END=logout


Sample Ini files are attached.


#Credits & thanks:
----------------------
https://github.com/easylogging/easyloggingpp - I used for logging
https://github.com/brofield/simpleini - To read Ini files