How to get the output of a console application from Java

Of course; I was trying to get a thread dump using jstack here. You would need to change the command that Runtime.exec() executes to your liking.

Process threadDump=Runtime.getRuntime().exec("jstack -l "+pid);
BufferedReader br=new BufferedReader(new InputStreamReader(threadDump.getInputStream()));
while(true)
{
String line=br.readLine();
if(line==null)
      break;
else {
      //Do whatever you want
}

Advertisements

How to get the process id after running an application from Java under Linux

Use the following sample code to get the pid(process id) on *nix variants, after running it as a command from Java using Runtime.exec() .

The command variable, in my case, was running another Java application.

try {

Process  process=Runtime.getRuntime().exec(new String [] {"sh","-c",command+"  &  echo $!"} );
BufferedReader br=new BufferedReader(new InputStreamReader(process.getInputStream()));

String ps=br.readLine();
int pid=Integer.valueOf(ps);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}

Oracle OCI8 Database Connection Problem #2 [Linux]

Hello folks,

Recently, I had another problem connecting to an Oracle 10g R2 database with the Oracle Call Interface. Well, this was not about the driver actually. Having passed 2 weeks from my first problem, this time I was deploying the servlet, Tomcat 6 and Oracle 10g R2 to a OpenSUSE 10.3 machine. It still was stopping at this line:

connection = DriverManager.getConnection(url, username, password);

Read the rest of this entry »