Batch File

varunrai

New Member
Messages
24
Reaction score
0
Points
0
Hi,

I am not sure if am posting in the correct section. But what I want to know that I have a Console App (i.e DOS App) and when I run that file it is asking for some inputs.

I wish to know is there any way i can create a batch script to automate the entry of the Application. Well I know I can change the App to get my values passed as arguments at the time of calling it. But that is not possible at the moment as the application is doing whole lot of other things.

So is there any way i can hook up the Application with Batch file to provide the entry into it. Or any other way it is possible.

Thanks in advance.
Varun

 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Hi,
I am not sure if am posting in the correct section. But what I want to know that I have a Console App (i.e DOS App) and when I run that file it is asking for some inputs.

Shell scripting is programming. Generally, this forum seems to be more about web scripts, but the forum description reads "all languages allowed", so why not?

I wish to know is there any way i can create a batch script to automate the entry of the Application. Well I know I can change the App to get my values passed as arguments at the time of calling it.[/url]

When it comes to the cmd shell, this is the best way of doing it. Read on for alternatives

But that is not possible at the moment as the application is doing whole lot of other things.

This I don't understand. Why exactly can you not use command line arguments? Are you trying to send commands to a currently running application without restarting it? Are you using command line arguments which are mutually exclusive to the arguments corresponding to the interactive directives you want to send to the app?

So is there any way i can hook up the Application with Batch file to provide the entry into it. Or any other way it is possible.

The other possibility presented by the cmd shell is redirection. You can redirect a file to stdin or pipe the output of another command into your apps stdin:
Code:
app < directions.txt
app2.exe | app.exe
In either case, I don't see how these would help as redirection must be set up when the command is launched, at which point you might as well use command line arguments. Furthermore any data sent to the app would be sent blind. The cmd shell doesn't have the utilities you'd find on a UNIX box to handle shell scripts (though you can find win32 ports; check out cygwin [you don't need to install the whole cygwin package; just cygwin.dll & whatever binaries you want, plus any dlls the binaries depend on])

More powerful than a batch program would be to pick a script host, such as cscript, and write a script in a language the script host supports (VBScript and JScript for cscript; if you want to use a .Net language, try nscript). In the script, create a shell object, run the app, then loop to process command output and produce input for the command. Here's a skeleton (untested & buggy)
Code:
cmd="/path/to/app args"
wsh = WScript.CreateObject("WScript.Shell")
cmdProcess=wsh.Exec(cmd)
while (! cmdProcess.StdOut.AtEndOfStream) {
    // get command output.  Need something more sophisticated to tell when command is waiting for input
    line = cmdProcess.StdOut.Read()
    // process line, generating a directive for the command
    ...
    cmdProcess.StdIn.Write(directive)
}

There are also non-MS script interpreters, such as Python and ActivePerl (or even ActiveTcl, if you want an easy way to add a graphical interface), that will do the job, along with the MS power shell, which I've barely used, but is indeed quite powerful. Imagine, for once MS isn't overstating some piece of their technology in a fit of marketing glee.
 
Top