wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Unable to get the output using StreamGobbler as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Unable to get the output using StreamGobbler as expected" Watch "Unable to get the output using StreamGobbler as expected" New topic
Author

Unable to get the output using StreamGobbler as expected

Prem Swaroop
Greenhorn

Joined: Apr 11, 2012
Posts: 8
I am using StreamGobbler class to display a shell script output in JTextArea. The shell script is getting executed successfully but even the first line of shell script is displayed as null.

Below is my shell script output when executed direcly from remote terminal :-

cinohappdi01sec:applgdev@/export/users/applgdev $ sh GESECSGITLY_US.sh
Log filename : L3246622.log


Report filename : O3246622.out
cinohappdi01sec:applgdev@/export/users/applgdev $

Below is my java code :-



Output at line 19 : The logfile name as : null
Expected Output at line 19 : The logfile name as : Log filename : L3246622.log

Can you please help me on this.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1077
    
  10

What is StreamGobbler? I don't find that in JDK. Is it your own class? Also, what is Session class?

From the code I understand that you are trying to execute a shell script and probably reading the output of that script which you expect to be a file name.
Executing an external process and reading/writing to that process is tricky and the usual methods don't work well.

I would like to point you out to an important link which highlights the issues and the solution too: link
This should give you an idea of how to deal with external executions.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 155
StreamGobbler ---> shot to the dark

Prem Swaroop
Greenhorn

Joined: Apr 11, 2012
Posts: 8
Sorry, I forgot to mention that I used Ganymed-SSH library. This library is used for SSH connection to remote servers. StreamGobbler class is in that package. It is used to collect the output/error from the shell itself. I have tried this for other commands like "date" etc. They work well, but this script doesn't.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1050
    
  10

Presumably this is not being run in the Swing event thread. You may have a deadlock. Until the remote process terminates your code sits in the loop reading stdout but what if there is a ton of output to stderr. At some point the stder buffer could fill so nothing more could be added to it and the remote process would have to be suspended and could never terminate. I always read stdou and stderr in different threads then this possible deadlock cannot happen.

Note - Ganymed is not my favourite Java SSH client library. I have found problems with it when trying to read large stdout and stderr where it loses data. Normally the first few hundred K of output is OK but then the process terminates and the streams appear to be empty even though they cannot be. This does not sound like your symptoms since you say you lose even the early output.
Prem Swaroop
Greenhorn

Joined: Apr 11, 2012
Posts: 8
My java program is able to execute the script remotely. The script is supposed to create a logfile and another file in the remote server. Both the files are getting created. So, my job is done. My only concern is that I am unable to get the output in the front end. According to Ganymed, getStdout() is supposed to collect the output from remote server. But that is not happening.

The output that my script produces is below :-

cinohappdi01sec:applgdev@/export/users/applgdev $ sh GESECSGITLY_US.sh
Log filename : L3246622.log


Report filename : O3246622.out
cinohappdi01sec:applgdev@/export/users/applgdev $
 
 
subject: Unable to get the output using StreamGobbler as expected