This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Unable to get the output using StreamGobbler as expected  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1104
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StreamGobbler ---> shot to the dark

 
Prem Swaroop
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 $
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!