I am making a console Java app where you can type in console commands like Terminal on Macintosh/Ubuntu/Windows Command Prompt and then it outputs it to a log.
I was wondering, when executing a system/console command, how I get the results/log from that command?
Note: I mean literal code + explanation please.
There are a number of ways to do this, the easiest is this (or a variant), from this example.
If you have internal commands you’d like to go to two places, consider something like a Commons IO TeeOutputStream.
You could combine the above techniques to get all output, whether from internal or external commands, to both your console, and a “shadow” log file.