i'm trying to remove junk files by using
Process p = Runtime.getRuntime().exec();
it works fine as long as i do not use wildcards, i.e. this works:
Process p = Runtime.getRuntime().exec("/bin/rm -f specificJunkFile.java");
while the following throws back "No such file or directory":
Process p = Runtime.getRuntime().exec("/bin/rm -f *.java");
i should be able to do all the nice things as outlined here, right?
getRuntime(). exec() method to use the command-line to run an instance of the program "tesseract". the first argument calls the tesseract program, the second is the absolute path to the image file and the last argument is the path and name of what the output file should be.
exec(String[] cmdarray, String[] envp) method executes the specified command and arguments in a separate process with the specified environment. This is a convenience method. An invocation of the form exec(cmdarray, envp) behaves in exactly the same way as the invocation exec(cmdarray, envp, null).
exec() method to call programs or commands from within your Java™ program.
The Java Runtime Environment (JRE) is software that Java programs require to run correctly. Java is a computer language that powers many current web and mobile applications. The JRE is the underlying technology that communicates between the Java program and the operating system.
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*" });
Those are Bash wildcards. They are interpreted within the Bash shell. You are running rm directly, so there is no shell to interpret the *
as 'all files'.
You could use bash as the command. e.g.:
Runtime.getRuntime().exec("/path-to/bash -c \"rm *.foo\"")
Might I suggest that you let Java do this for you?
Advantage: improved portability, saves the cost of an exec()
Runtime.getRuntime().exec(new String[] { "sh", "-c", "gunzip *.gz" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With