0

If I use System.out.print("Hello World") and run it in my IDE, it prints to the IDE output. If I compile it into a .jar file and run it from the terminal (mac) then it will print to the terminal; But if I just double click it and it doesn't have a GUI then it will not print anywhere. Is there a way to make it print in a certain app/exe like the terminal?

example:

Runtime runTime = Runtime.getRuntime();
Process process;
process = runTime.exec("open -a terminal");
[some code here]
System.out.print("Hello World");

and it prints hello world into the terminal

extra info: I'm using OSX and my IDE of choice is netbeans

EDIT: I don't want to print to a file, I want to print specifically to the terminal so that I can still receive input

  • Is your question "where does it go?" or is your question "Is there a way to open a terminal and print things to it?"? – user253751 Feb 21 '15 at 06:02
  • 1
    one solution would be create ur own GUI. for console print. – Rod_Algonquin Feb 21 '15 at 06:03
  • The output goes to standard output. Where that goes depends on how the java VM process was launched. You can however redirect this within your program, for example as already suggested to a file or potentially capture it yourself and push it into a window created with a java GUI toolkit, or by launching your jvm within something else which will capture and display the output. – Chris Stratton Feb 21 '15 at 06:08
  • I don't want a GUI and my question is how to tell it where to go. I found a command that is something like System.setOut(). Is this my answer? and if it is how do I use it? – Danny Sedlov Feb 21 '15 at 06:09

2 Answers2

1

print it in a file in terminal using java jar filename.jar > output.out output file is saved in your current directory.

1

It prints to stdout. To make output go somewhere else you can redirect stdout to print to some other stream, e.g. a file. See for instance:

System.out to a file in java

In which case, if you want to "double click" something you should create a shortcut that launches your program with a command line that redirects the output.

Community
  • 1
  • 1
amahfouz
  • 2,328
  • 2
  • 16
  • 21