简体   繁体   中英

Passing arguments to an executable using a batch file/command line

So there is a program someone wrote (that I don't have access to) that was written in C#, in which when I open it, it brings up a command prompt, asks several questions, and then returns an output.

What I want to do it write a batch file to automate entering all the arguments manually but nothing has really worked for me thus far. I tried "program.exe arg1 arg2.." in the command prompt and reading about the windows commands (I checked out ss64) but nothing seems to work.

So to summarize what happens is:

1) I open the program (a .exe file) in the command prompt (or click on it) where it asks me to enter a value or filename http://i.stack.imgur.com/bZsSi.png

2) I press enter to continue to the next question and the command asks me to answer another question (unless I finished the last one, in which case the program finishes executing and then closes). http://i.stack.imgur.com/nqJ5M.png

Now, how would I go about making a batch file that enters SWAIN.dat, n, 1000, etc... automatically into this program? Again, I don't have access to the original program. i only know it was written in C#.

Thank you very much.

You could create a VB script -

set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run "cmd" 
WScript.Sleep 100 
WshShell.AppActivate "C:\Windows\system32\cmd.exe" 
WScript.Sleep 100 
WshShell.SendKeys "program.exe{ENTER}" 
WScript.Sleep 100 
WshShell.SendKeys "SWAIN.dat{ENTER}" 
WScript.Sleep 100
WshShell.SendKeys "1000{ENTER}"

etc...

You may try this:

(
echo SWAIN.dat
echo n
echo 1000
echo etc...
) | program.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM