How to Run Windows Commands in Java and Store Their Output in Log File
In our day to day work we need to run windows commands and verify their output. In order to automate these frequently used commands, we normally write them in batch file but this option does not produce log like file and does not have good file formatting features.To solve this problem, below given utility program can serve just the right purpose. Here we make use of java.io class to write output file and make use of java's Runtime class methods to execute windows commands. Below is the code, that will run windows commands and store their output in a .txt file with formatting and date of run of commands. Complete code is available at my GitHub Project to change it to suite your needs. import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.File ; import java.io.FileWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Date ; public class RunningWinCmd { public st...