简体   繁体   English

使用批处理文件/命令行将参数传递给可执行文件

[英]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. 因此,有一个人用C#编写的程序(我无权访问),当我打开它时,它会弹出命令提示符,询问几个问题,然后返回输出。

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. 我在命令提示符下尝试了“ program.exe arg1 arg2 ..”,并阅读了有关Windows命令的信息(我检查了ss64),但似乎无济于事。

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 1)我在命令提示符下打开程序(.exe文件)(或单击它),它要求我输入值或文件名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). 2)我按Enter键继续下一个问题,命令要求我回答另一个问题(除非我完成了最后一个问题,在这种情况下程序将完成执行,然后关闭)。 http://i.stack.imgur.com/nqJ5M.png 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? 现在,我将如何制作一个将SWAIN.dat,n,1000等自动输入该程序的批处理文件? Again, I don't have access to the original program. 同样,我无权访问原始程序。 i only know it was written in C#. 我只知道它是用C#编写的。

Thank you very much. 非常感谢你。

You could create a VB script - 您可以创建一个VB脚本-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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