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.

  • 1
    Balram, can you share with us what the program is and what the inputs are? – N8sBug Jun 6 '14 at 10:25
  • I hate to break it to you, but it's Sending INPUT not reading input. If anything you're WRITING input not reading it. Besides the fact that it's in Windows, you're using the command prompt that's not DOS. i have corrected your question on that. – barlop Jun 6 '14 at 18:12
  • Thanks for your prompt reply Mr. Barlop. Actually my limitation is to feed data to .exe file through .Bat file only. – Balram Jun 16 '14 at 9:17
  • @Balram i'm pretty sure batch language can't, or can't in a sophisticated way.For example, u can do C:\>echo sdf | pause or echo y | del a.abut send data to a program including multiple return keys, nope.If there was a command that does it(somebody, maybe pc magazine,wrote one unce for MS-DOS ) that can send keys, but I don't know of such a third party app.QBASIC and layer, VBscript,and now,powershell.They exist because of limitations of the batch language.vbscript is native and That vbscript code will run from command line if u have cscript.exe Why do you have the 'only batch' limitation? – barlop Jun 16 '14 at 9:46
  • Thanks once again.In ours organization we does not have any language installed on systems (means no C, VC++ nor VB). I told that i know very little about programming language that is also only c & vc++ which is currently not installed in our organization. So that is why i have concluded that i have limitation of batch FILE. I would also appreciate if u can tell me any other solution other than batch file to run .exe file & pass input.As now you knows my limitations also. Thanks in advance – Balram Jun 23 '14 at 9:22

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}"
  • Thanks for your prompt reply Mr. Barlop. Actually my limitation is to feed data to .exe file through .Bat file only. So could you please guide me for batch file work on this problem. – Balram Jun 16 '14 at 9:17

I have found the easiest way is to use this code:

@echo off set /p input= echo %input%>example.txt

Hope this helps!


I think the problem had been miss-interpreted.

If input to the program normally goes:

> program
Enter input1:   A
Enter input2:   B
Enter input3:   C
Enter input4:   D

Then to simplify operation make up a text file (program.inp) as:


And then run it as:

> program <program.inp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.