Looking for sample Java code for running local CLI windows application
Hello,
We just installed an IBM DS8300 storage subsystem which is managed by CLI (command line interface). I'm looking for some sample java code to connect (login) into CLI and extract information.
I was looking into JNI but I think that is for calling C or C++ programs. What t I need is login into a native Windows application. Preferably in multithreaded mode so I can execute 20+ commands simultaneously.
Your advice would be highly appreciated.
Regards,
Ulises
[508 byte] By [
arsia] at [2007-11-27 6:45:53]

You seem to be saying several things at once.
Whatever this application is, you should check to see if there's already a Java API provided for it. It wouldn't surprise me if there is if IBM is the maker.
I'm confused what you mean by "multithreaded mode" for a command-line interface. Most human/computer interfaces are designed for a human to do a single thing at a time, and even more so with command-line interfaces.
If you have a program that has a command-line interface, then among other things you can use java.lang.Runtime.exec and java.lang.Process to run the interface and interact with it. Whether the application is native Windows or not is irrelevant.
Thanks for the response.
I found this code (see below) which is working like a champ but it's simgle threaded though.
I tried to make it multitasking by extending class Thread but it hangs and just wouldn't work.
If you guys have any ideas how to make this class multi-tasking would be a greate help.
Regards,
Ulises
public class CmdTest {
public static void main(String[] args) throws java.io.IOException {
String outFile = "./ds8300/lshostconnect.txt";
PrintWriter bout = null;
try {
bout= new PrintWriter(new FileWriter(new File(outFile)));
} catch (IOException e) {
e.printStackTrace();
}
Runtime run = Runtime.getRuntime();
run.traceMethodCalls(true);
Process proc2 = run.exec("cmd /c dscli -user user -passwd "+
"password " +"lshostconnect -l");
BufferedWriter ot= new BufferedWriter(
new OutputStreamWriter(proc2.getOutputStream()));
BufferedReader br= new BufferedReader(
new InputStreamReader(proc2.getInputStream()));
BufferedReader er= new BufferedReader(
new InputStreamReader(proc2.getErrorStream()));
try {
String s;
while((s=br.readLine())!=null) {
System.out.println(""+s);
bout.println(s);
}
while((s=er.readLine())!=null) System.out.println("ERR:"+s);
bout.close();
System.exit(0);
}catch (Exception ie) { //catch (InterruptedException ie) {
System.out.println("Interrupted:"+ie.getMessage());}
}
}
arsia at 2007-7-12 18:18:03 >

Well, you can (and should) create multiple threads to read the various i/o streams from the exec'd process.
Furthermore, you could create additional threads to invoke this CLI.
But it's not clear to me why you'd want to do the latter.
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html