0

I am trying to use XML to speak to a server and return data using the following code. Once active the code seems to wait indefinitely. Other threads in the program still remain active. I have used simalar code to speak to the server with no issue before. Can anyone see whats wrong here?

final String dosCommand = "cmd /c omp -iX -u admin -w admin -h " + openvasIP + " -p " + openvasPort + " --xml=\"<get_reports report_id='" + reportID + "' format_id='a3810a62-1f62-11e1-9219-406186ea4fc5'/>\"";

                    final String location = "C:\\";
                    try {
                        final Process process = Runtime.getRuntime().exec(dosCommand + " " + location);
                        final InputStream in = process.getInputStream();
                        int ch;

                        while ((ch = in.read()) != -1) {
                            System.out.print((char) ch);
                            String taskOut = String.valueOf((char) ch);
                            jTextArea3.append(taskOut);

Nothing is outputted at all. Not event the command into System.out.print.

EDIT: This command is designed to download file data in TXT or PDF (its on TXT right now). If I run the command from the CMD and send it to a txt file I get this - command...

C:\>omp -h 192.168.0.13 -p 9390 -u admin -w admin --get-report 474b824a-79bd-419
5-98ab-80efb40faca8 --format a3810a62-1f62-11e1-9219-406186ea4fc5 > c:/book/test
er2.txt

The output...

lib   xml-Message:    asking for 1048576

lib   xml-Message: <= <authenticate_response status="200" status_text="OK"><role
>Admin</role><timezone>UTC</timezone></authenticate_response>

lib   xml-Message:    asking for 1048576

lib   xml-Message: <= <get_version_response status="200" status_text="OK"><versi
on>4.0</version></get_version_response>

lib   xml-Message:    asking for 1048576

lib   xml-Message: <= <get_reports_response status="200" status_text="OK"><repor
t type="scan" id="474b824a-79bd-4195-98ab-80efb40faca8" format_id="a3810a62-1f62
-11e1-9219-406186ea4fc5" extension="txt" content_type="text/plain">SSBTdW1tYXJ5C
j09PT09PT09PQoKVGhpcyBkb2N1bWVudCByZXBvcnRzIG9uIHRoZSByZXN1bHRzIG9mIGFuIGF1dG9tY
XRpYyBzZWN1cml0eSBzY2FuLgpUaGUgcmVwb3J0IGZpcnN0IHN1bW1hcmlzZXMgdGhlIHJlc3VsdHMgZ
m91bmQuClRoZW4sIGZvciBlYWNoIGhvc3QsIHRoZSByZXBvcnQgZGVzY3JpYmVzIGV2ZXJ5IGlzc3VlI
GZvdW5kLgpQbGVhc2UgY29uc2lkZXIgdGhlIGFkdmljZSBnaXZlbiBpbiBlYWNoIGRlc2NyaXB0aW9uL
CBpbiBvcmRlciB0byByZWN0aWZ5CnRoZSBpc3N1ZS4KClZlbmRvciBzZWN1cml0eSB1cGRhdGVzIGFyZ

and so on....

So - am i trying to do this the wrong way?

The resulting text file is perfect. I like the same data in a jTextArea ideally

Remotejon
  • 35
  • 9
  • I have two ideas: 1) The returned input stream is a NullInputStream that always returns -1 at each read attempt. Check it with a "System.out.println(in.getClass())" directly after getting the input stream. 2) The process that you started does not correctly flush its own output to the STD_OUT stream, or it writes to the STD_ERR stream. – Seelenvirtuose Mar 25 '14 at 12:50
  • A side note: An input stream is a byte stream. You should wrap it into an InputStreamReader (with an appropriate encoding), which itself can be wrapped into a BufferedReader for having the readLine() method. Directly casting the incoming bytes into a char might be dangerous. – Seelenvirtuose Mar 25 '14 at 12:52
  • Im getting class "java.io.BufferedInputStream" back from your first suggestion. If it helps - I can run the command from cmd - this is the start of it. I have sent the contents to a textfile like this... Ill add it above – Remotejon Mar 26 '14 at 20:20

0 Answers0