Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.IOException: Bad file descriptor

843810Oct 20 2008
I am using the following piece of code:-

private static void RunClientUpdater(){
boolean running=false;
boolean error = false;
logger.info("RunClientUpdater|Checking Whether the Updater is running");
try {
String line;
String query="c:\\WINNT\\system32\\tasklist.exe /FO CSV /v /nh";
Process p = Runtime.getRuntime().exec(query);
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (!line.trim().equals("")) {
// get the process id
logger.info("RunClientUpdater|line=>"+line);

String appname=line.substring(0,line.indexOf(","));
appname=appname.replaceAll("\"","");
String processid=line.substring(line.indexOf(",")+1,line.indexOf(",",line.indexOf(",")+1));
processid=processid.replaceAll("\"","");
String processname= line.substring(line.lastIndexOf(",")+1,line.length());
String user=line.substring(line.indexOf("\\")+1,line.indexOf(",",line.indexOf("\\")+1));
user=user.replaceAll("\"","");
processname=processname.replaceAll("\"","");
if((processname.length()>=3 && processname.substring(0,3).equals("N/A")) && appname.equals("javaw.exe") && user.equals(System.getProperty("user.name"))){
logger.info("RunClientUpdater|processname=>"+processname.substring(0,3));
logger.info("RunClientUpdater|Updater is running");
running=true;
break;
}

}
}
p.destroy();
input.close();
} catch (Exception err) {
error=true;
logger.error("RunClientUpdater",err);
}


if(running==false && error==false){
logger.info("RunClientUpdater|Starting Updater");
String startApp="javaw -jar "+"\""+System.getProperty("user.dir")+"\\ECTAClientUpdate\\ClockingClientUpdate.jar"+"\"";
logger.info("RunClientUpdater|startApp=>"+startApp);
try {
String directory=System.getProperty("user.dir")+"\\ECTAClientUpdate";
logger.info("RunClientUpdater|directory=>"+directory);
Process p = Runtime.getRuntime().exec(startApp,null,new File(directory));
} catch (IOException ex) {
logger.error("RunClientUpdater",ex);
}
}
}

and almost 80% of the times the program runs well, while just sometimes, randomly, it throws the following exception:-

13 Sep 08 11:01:28 ERROR [biz.autoscan.ta.clockingclient.clockingclient:RunC lientUpdater] - RunClientUpdater
java.io.IOException: Bad file descriptor
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder$ConverterSD.implRead(Unkn own Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at biz.autoscan.ta.clockingclient.clockingclient.RunC lientUpdater(clockingclient.java:867)
at biz.autoscan.ta.clockingclient.clockingclient.acce ss$1100(clockingclient.java:55)
at biz.autoscan.ta.clockingclient.clockingclient$1.ac tionPerformed(clockingclient.java:171)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

can someone help why this is happening?it does not happen all the time, only randomly. Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2008
Added on Oct 20 2008
0 comments
1,022 views