

mand("sh", "-c", "mkdir -p /home/java_w3schools/java/posts") Minimum = 10ms, Maximum = 12ms, Average = 11ms Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),Īpproximate round trip times in milli-seconds: Process process = processBuilder.start() ProcessBuilder processBuilder = new ProcessBuilder() command() method to add the commands to the process builder and need to invoke the start() method to start a new process on the underlying operating system.Įxample to ping using ProcessBuilder on Unix:

This class is used to create operating system processes. Print all the lines which is having exception word ignoring case in server.log Runtime.getRuntime().exec("sh -c grep -i 'exception' /home/java_w3schools/java/server.log) Runtime.getRuntime().exec("sh -c mkdir -p /home/java_w3schools/java/posts) Runtime.getRuntime().exec("sh -c chmod -R 777 /home/java_w3schools/start.sh") Ĭhanging the file permissions to read/write/execute to all users. Runtime class has a exec(String command) method that Executes the specified string command in a separate process.īefore invoking this method, we must ensure that running program on correct OS. Runtime.getRuntime().exec("sh -c ls /home/java_w3schools") Runtime.getRuntime().exec("cmd.exe /c dir C://")

#Exec unix on mac mac#
Linux, Windows, SunOS, Mac OS, HP-UX and AIX This statement, may return the following operating system names. Private String OS = System.getProperty("os.name").toLowerCase() Before running the command, we must know the operating system where the application is running.īy calling System.getProperty("os.name") method, we will get the OS name.
