javac filename.java //(This will compile the program)
java filename //(This will run the file)
import java.io.*;
public class CmdTest {
public static void main(String[] args) throws Exception {
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", "cd "C:Program FilesMicrosoft SQL Server" && dir");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) { break; }
System.out.println(line);
}
}
}
javac <yourfilename>.java
after that do:
java <yourfilename>
java -jar target/spring-cloud-gateway-keycloak-oauth2-0.0.1-SNAPSHOT.jar
java -jar target/product-service-0.0.1-SNAPSHOT.jar
fun excCommand(cmd: String) {
val rt = Runtime.getRuntime()
try {
rt.exec(arrayOf("cmd.exe", "/c", cmd))
} catch (e: IOException) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
C:UsersYour Name>javac MyClass.java