I am trying to run this perl script through java. below is my script
public class Log {
public static void main(String[] args) throws IOException {
Process proc =null;
try
{
String[] commandAndArgs = {
"cmd","/c","C:\\Users\\myscipt.pl"
};
proc = Runtime.getRuntime().exec(commandAndArgs);
int returncode = proc.waitFor();
if(proc.exitValue() == 0)
{
System.out.println("Command Successful");
try
{
BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line="";
System.out.println("Process Executed"+returncode);
while ((line = input.readLine()) != null) {
System.out.println(line);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
else{
System.out.println("Process Executed"+returncode);
System.out.println("Command Failure");
}
}
catch(Exception t)
{
t.printStackTrace();
System.out.println("Exception: "+ t.toString());
}
finally
{
proc.destroy();
}
}
}
So when i execute this script its runs perfectly. But as soon as i am replacing the script with below line
"perl","C:\\Users\\myscipt.pl"
It throws me return code 2 error. So, where am i wrong ?