EDIT This is my batchfile code to run a (.bat) File , and i try to convert the output of the bat into a Logfile ,but i dont want to set the name of the logfile automatically , for every bat i want to run , create a new logfile with a the name of the BatFile. Hope i could explain it well
private final static Logger LOGGER = LoggerFactory.getLogger(BatchFile.class);
public void BatchFile(File file) throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder(file.getAbsolutePath());
processBuilder.directory(file.getParentFile());
Process process = processBuilder.start();
Scanner scanner = new Scanner(process.getInputStream());
try (PrintStream out = new PrintStream(new FileOutputStream("C:\\temp\\my_log.log"))) {
while (scanner.hasNextLine()) {
String outputLine = scanner.nextLine();
LOGGER.info(outputLine);
out.print(outputLine);
}
scanner.close();
}
System.out.println(process.waitFor());
}
}
i would like to know if someone had the same problem. I try to use LoggerFactory to create LogFile for my program, for example:
I want to take the output of System.out.printl into a LogFile. Or printing all Errors or messages from console into the LogFile. Is it even possible?
Thanks
final Logger log = LoggerFactory.getLogger(NameOfClass.class);