How to run Linux commands in Java?

You can use java.lang.Runtime.exec to run simple code. This gives you back a Process and you can read its standard output directly without having to temporarily store the output on disk. For example, here’s a complete program that will showcase how to do it: import java.io.BufferedReader; import java.io.InputStreamReader; public class testprog { public static void … Read more

How to use “cd” command using Java runtime?

There is no executable called cd, because it can’t be implemented in a separate process. The problem is that each process has its own current working directory and implementing cd as a separate process would only ever change that processes current working directory. In a Java program you can’t change your current working directory and … Read more

Difference between ProcessBuilder and Runtime.exec()

The various overloads of Runtime.getRuntime().exec(…) take either an array of strings or a single string. The single-string overloads of exec() will tokenise the string into an array of arguments, before passing the string array onto one of the exec() overloads that takes a string array. The ProcessBuilder constructors, on the other hand, only take a … Read more

process.waitFor() never returns

There are many reasons that waitFor() doesn’t return. But it usually boils down to the fact that the executed command doesn’t quit. This, again, can have many reasons. One common reason is that the process produces some output and you don’t read from the appropriate streams. This means that the process is blocked as soon … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)