Home arrow static arrow Java Programming [Archive] - hi
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - hi
This topic has 5 replies on 1 page.

Posts:392
Registered: 3/7/03
hi  
Jul 6, 2004 2:13 AM



 
execProcess = rt.exec("cmd /c C:/prg.exe < "/in.txt > " + tempProgStore + "/pout.txt",null, "C:/");
while((System.currentTimeMillis() < (startTime + maxAllowTime))){ //for each test case
try{
if(execProcess.exitValue() == 0){
break;
}else{
break;//terminate the process abnormal???
}
}catch(IllegalThreadStateException itse){ //the process hasn't finished
}
}

some times when more than one user is executing the codes the first statement does not produce the output
 

Posts:392
Registered: 3/7/03
Re: hi  
Jul 6, 2004 9:02 AM (reply 1 of 5)



 
execProcess = rt.exec("cmd /c C:/prg.exe < C:/in.txt > C:/pout.txt",null, "C:/");

Tomcat server is used.
When many clients do the request at the same time the pout.txt files is output empty.
i dont know why?
 

Posts:21,719
Registered: 98-02-20
Re: hi  
Jul 6, 2004 9:09 AM (reply 2 of 5)



 
You're not using Runtime.exec properly, for starters:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

%
 

Posts:31,095
Registered: 4/30/99
Re: hi  
Jul 6, 2004 10:14 AM (reply 3 of 5)



 
Tomcat server is used.
When many clients do the request at the same time the
pout.txt files is output empty.
i dont know why?

They are all writing to the same output file at the same time. If you really have to do this sort of stuff in a servlet, then you'll need to synchronize the code that does it so that only only one client at a time can do the stuff.

You might also consider putting a little more thought into your post titles.
 

Posts:392
Registered: 3/7/03
Re: hi  
Jul 6, 2004 7:59 PM (reply 4 of 5)



 
execProcess = rt.exec("cmd /c C:/prg.exe < "/in.txt > " + tempProgStore + "/pout.txt",null, "C:/");

hi,
I am sorry, in the real situation the path of the files change to different folders.
which should work ok.

With your advice (by reading the link provided) I have changed the codes to as such.
but still some times the output file is produced empty for some clients
what am i doing wrong :(

// part of the codes
for(int i=1; i <= testcase; i++){ // Loop for getting the test case provided by the tutor
Process execProcess;
if((System.currentTimeMillis() < (startTime + (maxAllowTime*i)))){
File dir1 = null;
dir1 = new File(tempProgStore + "
");
execProcess = rt.exec(procPath,null,dir1);
BufferedWriter buffOut = new BufferedWriter(new OutputStreamWriter(execProcess.getOutputStream()));
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(execProcess.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(tempProgStore + "/pout" + i + ".txt")));
File f= new File(sampleOutputStore +"/in" + i + ".txt");
String fRead = fo.ReadFile(f);
buffOut.write(fRead);
buffOut.flush();
while((System.currentTimeMillis() < (startTime + maxAllowTime))){ //for each test case, wait for it to complete
try{
String line;
if ((line = bufferedreader.readLine())!= null) {
out.println(line);
out.flush();
}
if(execProcess.exitValue() == 0){
break;
}else{ break; }
}catch(IllegalThreadStateException itse){ //the process hasn't finished
}
}
buffOut.close();
bufferedreader.close();
out.close();
endTime = System.currentTimeMillis();
execProcess.destroy(); //destroy the executed process
}
try{
Process killProcess = rt.exec(killProc);
fo.WaitOper(killProcess);
}catch(IOException ie){
}
}

 

Posts:9,091
Registered: 8/15/01
Re: hi  
Jul 6, 2004 9:53 PM (reply 5 of 5)



 
When you post code, please use[code] and [/code] tags as described in [url=http://forum.java.sun.com/features.jsp#Formatting]Formatting Help[/url] on the message entry page. It makes it much easier to read.
 
This topic has 5 replies on 1 page.