We have python application for work with WebSphere queue. This application consists of two files (queue-tools, queue-tools.py) and few libs. queue-tools file is looking like this:
#!/bin/sh
$HOME/sh/tests/queue-tool.py $@
When I run queue-tool -h command on unix host I see next result:
queue-tool.py [-h] [-t host] [-q qmgr] [-c channel] [-s SecurityExit] [-w]
[-f [FILE]] [-put arg [arg ...]] [-get arg [arg ...]]
[-peek arg [arg ...]] [-inquire arg]
Queue Tool
optional arguments:
-h, --help show this help message and exit
-t host target host
-q qmgr queue manager
-c channel channel
So my question is how to run this command (queue-tools -h
) from java code and read output result? I use below code but it doesn't work:
public static void testScript() {
String line;
try {
String[] cmd = {"/bin/sh", "-c", "queue-tool -h"};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader in =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null) { //line is null so nothing to read
System.out.println(line);
}
in.close();
} catch (InterruptedException iEX) {
iEX.printStackTrace();
} catch (IOException ioEX) {
ioEX.printStackTrace();
}
}