Answers for "spring boot process builder that executes a command line command"

1

java processbuilder example

public static void main(String[] args) {
        ProcessBuilder processBuilder = new ProcessBuilder();

        // Run this on Windows, cmd, /c = terminate after this run
        processBuilder.command("cmd.exe", "/c", "ping -n 3 google.com");

        try {
            Process process = processBuilder.start();
			//This will block other tasks
            BufferedReader reader =
                    new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            int exitCode = process.waitFor();
            System.out.println("\nExited with error code : " + exitCode);

        } catch (Exception e) {
            e.printStackTrace();
        } 
}
Posted by: Guest on June-13-2020
0

how to run springboots processbuilder

@PostConstruct
	public void doLog()throws IOException {
		ProcessBuilder processBuilder = new ProcessBuilder();
		processBuilder.command("python3","hello.py");
		processBuilder.directory(new File("src"));

		processBuilder.start();
		log.info("the services is running");
	}
Posted by: Guest on August-28-2020

Code answers related to "spring boot process builder that executes a command line command"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language