I have a requirement to run an autosys batch job and then check for its status till its status changes to SU. I have written the following code, but it gives me the following exception:
CreateProcess error=2, The system cannot find the file specified
Code:
try {
String[] cmds = {
"C:\\Folder_Path\\plink.exe -ssh username@Server -pw Password",
"sendevent -E FORCE_STARTJOB -j job-name"};
Runtime r = Runtime.getRuntime();
Process p = r.exec(cmds);
InputStream std = p.getInputStream ();
OutputStream out = p.getOutputStream ();
InputStream err = p.getErrorStream ();
Thread.sleep (5000);
int value = 0;
String output = "";
if (std.available () > 0) {
System.out.println ("STD:");
value = std.read ();
//System.out.print ((char) value);
while (std.available () > 0) {
value = std.read ();
output+=(char) value;
}
}
if (err.available () > 0) {
System.out.println ("ERR:");
value = err.read ();
//System.out.print ((char) value);
while (err.available () > 0) {
value = err.read ();
output+=(char) value;
}
}
System.out.print (output);
p.destroy ();
}
catch (Exception e) {
e.printStackTrace ();
}
Your cmd should be:
String[] cmds = {"C:\\Folder_Path\\plink.exe", "-ssh", "username@Server", "-pw", "Password", "sendevent", "-E", "FORCE_STARTJOB", "-j", "job-name"};
First argument is executable name. With your cmd, it is giving error as it is unable to find "C:\Folder_Path\plink.exe -ssh username@Server -pw Password" .
Your exe is C:\Folder_Path\plink.exe, so it should be first argument.