Hi can somebody help at the earliest . My requirement is to download a file from the remote server and read it in order to insert into db. So, i have written a shell script that downloads the file. This has to be invoked by a java program, after downloading it has to be read by the java program. Please find the code below: it give me the below error:

java.lang.IllegalThreadStateException: process hasn't exited
[1/4/11 14:59:01:290 CST] 0000003b SystemErr     R 	at java.lang.UNIXProcess.exitValue(UNIXProcess.java:322)
[1/4/11 14:59:01:290 CST] 0000003b SystemErr     R 	at services.in.cat.CATInterfacing.callDCATJob(CATInterfacing.java:124)
[1/4/11 14:59:01:291 CST] 0000003b SystemErr     R 	at services.in.schedule.jobs.SchedulerJOBForcat.execute(SchedulerJOBForcat.java:31)
[1/4/11 14:59:01:291 CST] 0000003b SystemErr     R 	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[1/4/11 14:59:01:291 CST] 0000003b SystemErr     R 	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
---------------------------------------------------------------------------------

/*here is the program i have written  */




try {
			Runtime rt = Runtime.getRuntime();
			Process proc = rt.exec("/home/it/Test/current/catdownload.sh");
			int exitVal = proc.exitValue();
			System.out.println("Process exitValue: " + exitVal);

			proc.waitFor();
		} catch (Throwable t) {
			t.printStackTrace();
		}

try{
readtextfile();
}
catch(exception e)
{
}

Edited 5 Years Ago by ~s.o.s~: Added code tags; learn to use them.

Why not "write the download" in Java? How is it being downloaded? If by FTP google for an FTP library (apache provides one), if by http, see the API docs for HttpURLConnection, if by SSH see JSch.

However, I would ask why this needs to done in Java? If you already have a script that downloads the file, could not that same script simply call a DB utility to "load" it?

hi masijade,

thanks for the reply, well requirement is...i should not use any third party library. Secondly before inserting into table i need to validate based on some criteria.

Whatever. You need to wait on the process before trying to get the exit value. Google for a tutorial and read the API docs. You're still going about it all the wrong way, regardless. What is the reason for the opposition to libraries? Have you asked for any reasoning on that? Or is it just a clueless individual? Did you even ask? Didi you even attempt to convince them of the folly of that decision? Or did you just make that up so you could push your "solution"?

This article has been dead for over six months. Start a new discussion instead.