2

Pasting the code sample directly:

        Runtime rt = Runtime.getRuntime();
        path = "c:\IBM\WebSphere\AppServer\profiles\STSCDmgrProfile\bin\";
        cmd = path + "wsadmin";
        String cmdString = cmd
                + " -host "
                + host
                + " -port "
                + port
                + " -username "
                + username
                + " -password "
                + password
                + " "
                + "-f" + "c:/IBM/WebSphere/AppServer/profiles/STSCDMgrProfile/temp/mergedScripts.jy"
                + " -lang "
                + lang
                + " -tracefile logs/ssc_wsadmin_trace.txt -appendtrace true";
        _logger.finer(cmdString.replaceAll(" " + password, " <password>"));
        Process proc = rt.exec(cmdString);
        _logger.finer("Launched process");

        stdInput = new BufferedReader(new InputStreamReader(proc
                .getInputStream()));
        stdError = new BufferedReader(new InputStreamReader(proc
                .getErrorStream()));

        // read the output from the command
        String sIn = "";
        **while ((sIn = stdInput.readLine()) != null) {**
            _logger.log(Level.FINE, "runJCommand stin ==>", sIn);
        }

However it hangs while doing readLine() from the stdInput. Highlighted above. Following is what I see in the trace logs:

[7/30/13 23:48:04:937 GMT-12:00] 000000a6 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 1" (00000175) has been active for 664085 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be hung.
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:223)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:267)
at java.io.BufferedInputStream.read(BufferedInputStream.java:328)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:464)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:506)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:234)
at java.io.InputStreamReader.read(InputStreamReader.java:188)
at java.io.BufferedReader.fill(BufferedReader.java:147)
at java.io.BufferedReader.readLine(BufferedReader.java:310)
**at java.io.BufferedReader.readLine(BufferedReader.java:373)**
at com.ibm.sametime.console.admin.plugins.wsadmin.SSCWsAdmin.runJCommand(SSCWsAdmin.java:924)

If I run the same mergedScripts.jy (that I am calling in the java code above), manually through commandline, then it executes successfully and completes in a few mins. However through Java code it runs forever.

What could be the possible reasons? What actually is STDIN in the above case ?

Manuel
  • 3,828
  • 6
  • 33
  • 48
Abhijit
  • 21
  • 1

2 Answers2

0

In your example code you're reading from the InputStream, but not from the ErrorStream at all, your issue may be that the ErrorStream's buffer is full and this is causing the process to block or deadlock. See the "Why Runtime.exec() hangs" section in this article. The article goes on to describe how to avoid this, but you could simplify the process by using ProcessBuilder instead of Runtime.exec() and then redirecting the ErrorStream.

ProcessBuilder pb = new ProcessBuilder("wsadmin", "-host", host, "-port", port, "-username", username, ... );
Process proc = pb.redirectErrorStream(true).start();
//Read from the InputStread as you were...

What actually is STDIN in the above case ?

proc.getInputStream() will contain any output that running the wsadmin command would produce when you run it from the command line.

Syon
  • 7,205
  • 5
  • 36
  • 40
0

I'm not sure exactly what you are coding, but I once wrote something similar to what you are doing in perl. Perhaps you could adapt it to python.

my $line = "cd /usr/websphere/profiles/myProfile/bin;";
$line .= ($user !~ /root/i) ? ' sesudo' : '';
$line .= " ./wsadmin.sh -lang jython ";
$line .= "-f $wasscriptpth ".join(' ', @args);
$line .= " 2>&1";

Then I simply called the command on the shell and piped the output to a file handle...

open(SSHANDLE, "$line |")

Note the "2>&1" This was a really simple way to read the error and standard output in one place. Perhaps you could do something like this in python?

Threadicide
  • 126
  • 7