I run cmd (command line) and running my batch file from Java this way:
final String cmd = "cmd /c C: && dir && cd C:\MyApp\Maxi && dir && C:\MayApp\Maxi\deploy.bat";
try {
Process process = Runtime.getRuntime().exec(cmd);
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
} catch (IOException e) {
System.out.println("IOException on CMD executing statement");
e.printStackTrace();
}
It was working successfully, but I modified the batch file and added some argument, so I have to pass a name to the batch file so i tried this: (I send "Name1" as argument)
final String cmd = "cmd /c C: && dir && cd C:\MyApp\Maxi && dir && C:\MayApp\Maxi\deploy.bat Name1";
try {
Process process = Runtime.getRuntime().exec(cmd);
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
} catch (IOException e) {
System.out.println("IOException on CMD executing statement");
e.printStackTrace();
}
But its not working now and the command is not executed. I only get the "dir" command output.
Can anyone help ?
Note: The commands run successfully on CMD, but its not working from java.