How to makesure the runtime.exec completely execute the file?

Below is my code, actually the problem I'm facing is it not completely execute the file and this make an error because it cannot find the file, so how to make sure it  completely execute the file and after it complete the fileinputstream read the file.

Error:
java.io.FileNotFoundException: C:\apache-tomcat-6.0.18\webapps\grid40\grid_archive\testing_55a.sql (The system cannot find the file specified)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(FileInputStream.java:106)
      at java.io.FileInputStream.<init>(FileInputStream.java:66)
      at ExecuteBcp.main(ExecuteBcp.java:27)

BufferedWriter writer = null;
InputStreamReader irs = null;
BufferedReader br = null;
String path1="C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55a.sql";

String path2="C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55b.sql";
		
String execStr = "bcp audittrail.dbo.audit_trail out \"C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55a.sql\" -c -S 172.16.100.81 -U admin -P siti2138";

System.out.println("execute");
writer = new BufferedWriter(new FileWriter("C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55.sql"));
try {
			
Runtime runtime = Runtime.getRuntime();
Process child = runtime.exec(execStr);
writer = new BufferedWriter(new FileWriter(path2));
FileInputStream fis = new FileInputStream(path1);

irs = new InputStreamReader(fis);
br = new BufferedReader(irs);
	        
String line;
while( (line=br.readLine()) != null ) {
writer.write(line + "\n");
}
writer.close();
irs.close();
br.close();
			
			
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Open in new window

sitijaafarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sitijaafarAuthor Commented:
It's completely execute the file testing_55a.sql and an error message not appear anymore.  But it not create the file testing_55b.sql and when I try to print the exitCode value it's not appear. It's look like not go to the next process.
BufferedWriter writer = null;
InputStreamReader irs = null;
BufferedReader br = null;
String path1="C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55a.sql";
String path2="C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55b.sql";
		
String execStr = "bcp audittrail.dbo.audit_trail out \"C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55a.sql\" -c -S 172.16.100.81 -U admin -P siti2138";

System.out.println("execute");
writer = new BufferedWriter(new FileWriter("C:\\apache-tomcat-6.0.18\\webapps\\grid40\\grid_archive\\testing_55.sql"));
try {
			
Runtime runtime = Runtime.getRuntime();
Process child = runtime.exec(execStr);			
int exitCode = child.waitFor();
			
System.out.println("exitCode"+exitCode);
writer = new BufferedWriter(new FileWriter(path2));
FileInputStream fis = new FileInputStream(path1);

irs = new InputStreamReader(fis);
br = new BufferedReader(irs);
	        
String line;
while( (line=br.readLine()) != null ) {
writer.write(line + "\n");
}
writer.close();
irs.close();
br.close();
			

Open in new window

0
Mick BarryJava DeveloperCommented:
if the process produces any output to stdout/stderr then you need to read it

http://helpdesk.objects.com.au/java/runtime-exec-locks-up
0
Pramod KumarCommented:
You should use separate thread for in , out, err
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.