简体   繁体   English

在Windows上从批处理脚本执行多个命令

[英]Executing multiple commands from a batch script on Windows

I'm using the below bat script on Windows. 我在Windows上使用下面的bat脚本。 The first line of my batch script executes a jar that starts by printing a menu prompt within the shell. 我的批处理脚本的第一行执行一个jar,它通过在shell中打印菜单提示开始。 I'd like the subsequent lines of the script to be used as input while executing in the jar (for example, to choose the first menu option, then input a users first name, then a users last name). 我想在jar中执行时将脚本的后续行用作输入(例如,选择第一个菜单选项,然后输入用户名,然后输入用户姓)。

I tried the Windows call and start commands, but either didn't use the right options or was doing something wrong since I've always ended up receiving the "is not recognized as an internal or external command, operable program or batch file" error for each subsequent line in the script. 我尝试了Windows 调用启动命令,但要么没有使用正确的选项,要么做错了,因为我总是收到“未被识别为内部或外部命令,可操作程序或批处理文件”错误对于脚本中的每个后续行。

test.bat test.bat的
java -classpath %LIBRARY_PATH% sample.Test java -classpath%LIBRARY_PATH%sample.Test
1 1
FName FName参数
LName LName的

You need to put your inputs in a separate file and than redirect your program to read inputs from the file like this: 您需要将输入放在单独的文件中,然后重定向程序以从文件中读取输入,如下所示:

test.bat test.bat的

[command] < [file]

[command] would be your command to launch the java program and [file] would be the full path to the file containing rest of the inputs. [command]将是启动java程序的命令, [file]将是包含其余输入的文件的完整路径。

(
  echo 1
  echo FName
  echo LName
) | java -classpath %LIBRARY_PATH% sample.Test

Be careful with what you echo, since there are some special cases. 因为有一些特殊情况,所以要小心你的回声。

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

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