Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij stdin rederection

What is a difference how Idea run Batch configuraton compare to pure cmd.exe in windows?

I create batch config for run my java app. When I run it, it show me result scipt in Idea console:

cmd.exe /c java -classpath C:\app;C:\app\libs.jar App < input.txt

This app waiting input from standard input. This line should run it and read from input.txt file. But insted of reading it waiting for input. When i press ^D in Idea console, App prints me that No inputs was.

In same time when i copy paste this starting script from Idea console direct to Windows cmd, everything happen as expected, App reads the file and finish correctly.

I did read stackoverflow answers and find suggestions to try External Tool Idea option. I try run it as:

java -classpath C:\app;C:\app\libs.jar App < input.txt

But it still waiting for input. As well as Java Application run configuration if I pass file name as argument, it wait for input:

"C:\Program Files\Java\jdk1.8.0_92\bin\java"
 -Didea.launcher.port=7533
"-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IDEA\bin"
 -Dfile.encoding=UTF-8
 -classpath "long..long..classpath"
 com.intellij.rt.execution.application.AppMain Col < input.txt

I did find few links (one,two,three) about stdin rederection and it seems like there is no way to do this from idea only from code. Thank you!

like image 629
Ivan Bryzzhin Avatar asked Dec 19 '22 16:12

Ivan Bryzzhin


1 Answers

The only way I did find is pass filename as argument to main function and add line like this:

if(args.length > 1)
    System.setIn(new FileInputStream(args[1]));
like image 76
Ivan Bryzzhin Avatar answered Jan 04 '23 14:01

Ivan Bryzzhin