Java Runtime.getRuntime().exec() alternatives

I found a workaround in this article, basically the idea is that you create a process early on in the startup of your application that you communicate with (via input streams) and then that subprocess executes your commands for you. //you would probably want to make this a singleton public class ProcessHelper { private OutputStreamWriter … Read more

Using Quotes within getRuntime().exec

Use this: Runtime.getRuntime().exec(new String[] {“sh”, “-l”, “-c”, “./foo”}); Main point: don’t put the double quotes in. That’s only used when writing a command-line in the shell! e.g., echo “Hello, world!” (as typed in the shell) gets translated to: Runtime.getRuntime().exec(new String[] {“echo”, “Hello, world!”}); (Just forget for the moment that the shell normally has a builtin … Read more

Running Bash commands in Java

You start a new process with Runtime.exec(command). Each process has a working directory. This is normally the directory in which the parent process was started, but you can change the directory in which your process is started. I would recommend to use ProcessBuilder ProcessBuilder pb = new ProcessBuilder(“ls”); pb.inheritIO(); pb.directory(new File(“bin”)); pb.start(); If you want … Read more

Redirection with Runtime.getRuntime().exec() doesn’t work

The problem is, the redirection character (>) is a shell-based construct, not an executable. So unless you’re running this command through something like bash (which you’re not), it’s going to be interpreted as a literal character argument to your exiftool invocation. If you want to get this to work, you have two options: Get bash … Read more

tech