开发者

.bat file interaction with java or C#.net GUI application

开发者 https://www.devze.com 2023-04-08 05:04 出处:网络
How to interact .bat file with java or C#.net GUI application? Here is part of my .bat code. :Valid echo Enter student id:

How to interact .bat file with java or C#.net GUI application? Here is part of my .bat code.

:Valid

echo Enter student id:

set/p "pass=>"

开发者_StackOverflow中文版if NOT %pass%== UserStudentId goto FAIL

When I run the .bat file it will ask Enter student id: in command prompt, then validate the student id and do some process. I want to pass this input from java or C#.net IDE to .bat file and continue the process. In here User will never deal with command prompt. If there is any output from .bat , it will show in java or .net IDE also.

I wonder if it is possible since I'm new to this. TX.


When you start a process from Java or C# you can get console input and output of that process as streams. You then can simply write into the process' input stream.

It might be, though, that the batch file won't actually like that since cmd might look for actual interactive input with set /p (e.g., it fails with file redirection, if I remember correctly). A better method, if you control the batch file itself, would be the following:

if defined pass goto SkipInput
set /p pass=Enter student ID:
:SkipInput

which will use an environment variable if present and only ask the user if it isn't already set. This is much more automation-friendly, since you can just set the environment variable in the calling process and have it inherited for every process you spawn. And no hassle with emulating input as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号