Windows – Sending input to command line program from text/Batch file

batchinputwindows

I am a mechanical engineer with some hand on Programming in VC++.
Our industry uses a DOS program & that requires 8 user inputs. We have to feed it manuaaly every time.
Does we can automate this process by putting input in a Text file / batch file. We want to automate this process of feeding data to command line program.

It will be totally my pleasure to get some answer based upon your experiences.

Best Answer

assuming the program doesn't have a method already like taking a parameter with the input or input file, then it sounds like a programming problem of automatically sending keys to a program. VBscript has SendKeys. VC++ no doubt has that or equivalent. otherwise it's autohotkeys/autoit. But look up any example of sendkeys in vbscript and you'll see an example.

Try the copy con command manually to see how it works. copy con c:\blah\a.a

then you enter the text of the file, and hit Ctrl-Z to write it.

So that involved entering things on the command line.

And try this vbscript which does that automatically

for command line. call this whatever.vbs

dim a
a="copy con c:\blah\file.123"
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.SendKeys a
WshShell.SendKeys "dsdsfd{ENTER}sdfds{ENTER}sleep for 2000ms and will enter more{ENTER}"
Wscript.Sleep 2000
WshShell.SendKeys "ewrwrewrewwe{ENTER}"
WshShell.SendKeys "sending ctrl-z and enter {ENTER}"
Wscript.Sleep 2000
WshShell.SendKeys "^Z{ENTER}"
Related Question