D
dagreat
Hello,
I am trying to report system print queue statuses at specified
intervals. I am using java.util.Timer to implement a repeating task
that does this. My code executes properly when run without using
java.util.Timer. However, it does not work when using Timer.
--------------------------------------------------
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
Timer timer = new Timer(false);
// get time interval randomly. The interval will be somewhere
between
// 9 and 11 minutes.
GregorianCalendar now = new GregorianCalendar();
Random randomGen = new Random(now.getTimeInMillis());
int intervalVariance = randomGen.nextInt(maxIntervalVariance);
//long interval = minInterval + intervalVariance;
long interval = 3000;
// Create The task
StatusReportTask task = new StatusReportTask(util);
timer.schedule(task,now.getTime(),interval);
--------------------------------------------------
The code seems to be breaking when making a system call to get a list
of print queues on the system...
String[] cmd = { "/bin/sh", "-c", "lpstat -p | awk '/^printer/ {print
$2}'" };
----------------------------------------------------
Vector queues = new Vector();
Runtime rt = Runtime.getRuntime();
rt.traceInstructions(true);
String[] cmd = { "/bin/sh", "-c", "lpstat -p | awk '/^printer/
{print $2}'" };
try {
Process p = rt.exec(cmd);
String line;
// read STDOUT from command
BufferedReader input = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (line != null && line.trim().length() > 0 )
queues.add(line.trim());
}
input.close();
int waitRet = p.waitFor();
int exitValue = p.exitValue();
System.out.println("exitValue:"+exitValue);
} catch (Exception e) {
throw new Exception(e.getMessage()+ ": Could not get print queue
list.");
}
String[] strs = new String[queues.size()];
return (String[])queues.toArray(strs);
}
--------------------------------------------------
What seems to be happening is that I lose the process after executing
it. It never seems to return (The exit value does not get printed- as
it should) and an exception is never caught. It seems that no code is
executed after I call and waitFor the process... except my shutDownHook
is printing some output. and also... the app should not terminate
because Timer() should keep it running until explicitly killed.
However, it is terminating following the p.exec() call.
Any ideas?
thanks
I am trying to report system print queue statuses at specified
intervals. I am using java.util.Timer to implement a repeating task
that does this. My code executes properly when run without using
java.util.Timer. However, it does not work when using Timer.
--------------------------------------------------
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
Timer timer = new Timer(false);
// get time interval randomly. The interval will be somewhere
between
// 9 and 11 minutes.
GregorianCalendar now = new GregorianCalendar();
Random randomGen = new Random(now.getTimeInMillis());
int intervalVariance = randomGen.nextInt(maxIntervalVariance);
//long interval = minInterval + intervalVariance;
long interval = 3000;
// Create The task
StatusReportTask task = new StatusReportTask(util);
timer.schedule(task,now.getTime(),interval);
--------------------------------------------------
The code seems to be breaking when making a system call to get a list
of print queues on the system...
String[] cmd = { "/bin/sh", "-c", "lpstat -p | awk '/^printer/ {print
$2}'" };
----------------------------------------------------
Vector queues = new Vector();
Runtime rt = Runtime.getRuntime();
rt.traceInstructions(true);
String[] cmd = { "/bin/sh", "-c", "lpstat -p | awk '/^printer/
{print $2}'" };
try {
Process p = rt.exec(cmd);
String line;
// read STDOUT from command
BufferedReader input = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (line != null && line.trim().length() > 0 )
queues.add(line.trim());
}
input.close();
int waitRet = p.waitFor();
int exitValue = p.exitValue();
System.out.println("exitValue:"+exitValue);
} catch (Exception e) {
throw new Exception(e.getMessage()+ ": Could not get print queue
list.");
}
String[] strs = new String[queues.size()];
return (String[])queues.toArray(strs);
}
--------------------------------------------------
What seems to be happening is that I lose the process after executing
it. It never seems to return (The exit value does not get printed- as
it should) and an exception is never caught. It seems that no code is
executed after I call and waitFor the process... except my shutDownHook
is printing some output. and also... the app should not terminate
because Timer() should keep it running until explicitly killed.
However, it is terminating following the p.exec() call.
Any ideas?
thanks