简体   繁体   中英

Executing multiple commands from a batch script on Windows

I'm using the below bat script on Windows. The first line of my batch script executes a jar that starts by printing a menu prompt within the 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).

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.

test.bat
java -classpath %LIBRARY_PATH% sample.Test
1
FName
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

[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.

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

Be careful with what you echo, since there are some special cases.

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