package com.example.demo; import org.springframework.stereotype.Component; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.Collectors; @Component public class cmd { public String run(String cmd) throws IOException { String line = null; Process r = Runtime.getRuntime().exec(cmd); InputStreamReader in = new InputStreamReader(r.getInputStream()); BufferedReader br = new BufferedReader(in); return br.lines().collect(Collectors.joining("</br>")); } }