java - Automating jar input -


i have jar file asks user value of n. , adds values entered. when jar executed cmd.exe, works well. when invoked .bat file, not prompting input rather executes further statements. tried using pipe,as,

(echo 3 echo 10 echo 20 echo 30)| java -jar add.jar

but didn't work.how can automate input?

note: values not accepted arguments, prompt.

without knowing code it's hard tell why it's not working you.

see below simple working example

add.java

import java.util.scanner;  public class add {     public static void main(string[] args) {         scanner scanner = new scanner(system.in);         int sum = 0;         while (scanner.hasnextint()) {             int value = scanner.nextint();             sum += value;             system.out.println("sum = " + sum);         }     } } 

run.bat

@echo off (echo 2 echo 10 echo 20 echo 30 echo end ) | java -jar add.jar 

compile , build jar

javac add.java echo main-class: add > manifest.mf jar cmf manifest.mf add.jar add.class 

run batch file

run.bat 

output

sum = 2  sum = 12 sum = 32 sum = 62 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -