I'm very new in java and trying to figure out why i'm getting a standard error output of "/usr/bin/find: incomplete statement" --->"find /export/home -type f -mtime +30 -exec rm {} \;" } using java program but executing manually the "find" script command using CLI on solaris Unix os it works fine.
Here is the code:
import java.io.*;
public class PurgeLog
{
//script to remove files older than 30 days
public static String CmdList = { "find /export/home -type f -mtime +30 -exec rm {} \;" };
public static void main (String[] args)
{
System.out.println("You are about to purge files older than 30 days ....... [Y/N]: ");
String s = null;
String name = null;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
name = br.readLine();
if (name.equalsIgnoreCase("Y"))
{
System.out.println("Starting to purge Old LogFiles, Pls Wait........\n");
System.out.print("");
System.out.println("Executing--->"+CmdList);
Process p = Runtime.getRuntime().exec(CmdList);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Standard output of the command:\n");
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
//System.out.println("Exit Value " + exitval);
// read any errors from the attempted command
System.out.println("Standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
//int exitval = p.waitfor();
}
int exitIn = p.waitFor();
int exitOut = p.waitFor();
}
else
{
System.out.println("Not continuing......Thanks");
System.exit(-1);
}
} //try
catch (IOException e)
{
System.out.println("Error!--->"+e.getMessage());
System.exit(-1);
}
catch (Throwable t) { t.printStackTrace();}
}
}
Any help would be gladly appreciated.Thanks in advance.
Here is the code:
import java.io.*;
public class PurgeLog
{
//script to remove files older than 30 days
public static String CmdList = { "find /export/home -type f -mtime +30 -exec rm {} \;" };
public static void main (String[] args)
{
System.out.println("You are about to purge files older than 30 days ....... [Y/N]: ");
String s = null;
String name = null;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
name = br.readLine();
if (name.equalsIgnoreCase("Y"))
{
System.out.println("Starting to purge Old LogFiles, Pls Wait........\n");
System.out.print("");
System.out.println("Executing--->"+CmdList);
Process p = Runtime.getRuntime().exec(CmdList);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Standard output of the command:\n");
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
//System.out.println("Exit Value " + exitval);
// read any errors from the attempted command
System.out.println("Standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
//int exitval = p.waitfor();
}
int exitIn = p.waitFor();
int exitOut = p.waitFor();
}
else
{
System.out.println("Not continuing......Thanks");
System.exit(-1);
}
} //try
catch (IOException e)
{
System.out.println("Error!--->"+e.getMessage());
System.exit(-1);
}
catch (Throwable t) { t.printStackTrace();}
}
}
Any help would be gladly appreciated.Thanks in advance.