java Runtime.getRunTime().exec & wildcards?
After a lot of searching I found this: http://www.coderanch.com/t/423573/java/java/Passing-wilcard-Runtime-exec-command Runtime.exec(new String[] { “sh”, “-c”, “rm /tmp/ABC*” });
After a lot of searching I found this: http://www.coderanch.com/t/423573/java/java/Passing-wilcard-Runtime-exec-command Runtime.exec(new String[] { “sh”, “-c”, “rm /tmp/ABC*” });
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
To use it with ProcessBuilder you must separate the commands like this: final List<String> commands = new ArrayList<String>(); commands.add(“cmd.exe”); commands.add(“/C”); commands.add(“start”); ProcessBuilder pb = new ProcessBuilder(commands); pb.start();
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
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
If I’m not mistaken, the “ffmpeg-wrapper” project you linked to is out of date and not maintained. FFmpeg is a very active project, lot’s of changes and releases all the time. You should look at the Xuggler project, this provides a Java API for what you want to do, and they have tight integration with … Read more
I’ve struggled with the same kind of issues. I can’t remember what exactly was wrong (maybe I forgot to flush / close the streams correctly or something …). Anyway, here is what I came up with. /** * Handle communication with a process, reading its output/error and feeding its input * @param process The process … Read more
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
Runtime.getRuntime().exec(“netsh”); See Runtime Javadoc. EDIT: A later answer by leet suggests that this process is now deprecated. However, as per the comment by DJViking, this appears not to be the case: Java 8 documentation. The method is not deprecated.
It is a bit strange but you can run the second program without forking it. Just calling the main method in it. So forget the runtime section and do this: sam2.main(new String[0]); Of course this way you must compile sam2 at compile time