See if this works (sorry can't test it right now)
Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});
Answer from Chris Stratton on Stack OverflowSee if this works (sorry can't test it right now)
Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});
Use ProcessBuilder instead of Runtime#exec().
ProcessBuilder pb = new ProcessBuilder("php", "/var/www/script.php", "-m 2");
Process p = pb.start();
You are not capturing STDERR, so when errors occur you do not receive them from STDOUT (which you are capturing). Try:
BufferedReader input = new BufferedReader(new InputStreamReader(
pr.getErrorStream()));
well tesseract is external command so you do not need to use it with cmd. Add tesseract to environment variables. Use direct command as :
String[] commands = {"tesseract", imageFilePath, outputFilePath };
Exist status 1 means Incorrect function. See process exit status
+1 for sending the arguments through as an array.
Sending everything through as a string may work on some systems but fail on others.
Process start = Runtime.getRuntime().exec(new String[]
{ "java", "-version" });
BufferedReader r = new BufferedReader(
new InputStreamReader(start.getErrorStream()));
String line = null;
while ((line = r.readLine()) != null)
{
System.out.println(line);
}
I know you have said that you tried sending the arguments through as an array of Strings without success but were you receiving a different type of error? If that other program has a log you might want to see what is going wrong. You could write a simple script that outputs the parameters it was called with to test what is actually coming through.
Use ProcessBuilder and pass it a String[]
String[] cmmm = {arg3,arg4,arg5, arg6,arg7 };
ProcessBuilder pb = new ProcessBuilder(cmmm);
pb.directory(new File(tDir));
Process p = pb.start();
You simply can't use pipes in a exec call. Pipes are a functionality of the shell and not of the operating system. So we have to call the shell executable and pass the command. Try this instead:
String[] command = new String[] {"cmd.exe", "/c", "start webRestarter.exe", ">>","webLog.log"};
Parameters are passed directly to the webRestarter.exe command. You can't use parameters to redirect standard output to a file, as this is usually done by your command line interpreter.
However, the exec() method returns a Process object, which you could use to retrieve standard output and write it to a file.
Sources:
http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#exec%28java.lang.String%29
http://download.oracle.com/javase/6/docs/api/java/lang/Process.html
Are you familiar with the exec double-quotes bug? (for Runtime.exec or ProcessBuilder)
You can try:
Runtime.getRuntime().exec(new String[] {
"\"C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump\"",
"-h",
hostName+user+databaseName});
Just make sure none of your parameters you will have to pass contains double quotes (while not beginning with double quotes)
(see bug 6511002)
Any parameter like:
mykey="my value with space"
would be changed internally (by the getRuntime() implementation) into
"mykey="myvalue with space""
If that is the case, you would need to tokenize the argument:
{"mykey=\"my\"" , "\"value with space\""}
The file path contains blanks, that may be (one of) the problem(s). Try this instead:
dumpCommand = "\"C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump\" -h"
+hostName+user+databaseName;
and follow phisch's suggstion to print the dumpCommand String to double check that it's a valid mysqldump call
Run the script in the command line and if it Works just copy that string and pass it to getRuntime.exec(string) Also you should specify which programm will execute the script, i'm guessing in this case should be cmd.exe
This did the trick:
rt.exec(new String[]{"/bin/sh", "-c", "find "+path+"* -mtime +1 -exec gzip -q {} \\;"});
The interpreter /bin/sh was needed, and the rest of the command can go as single argument to .exec().