• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

return or output stream?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm trying to find a way to return a string from 'streamgrabber'.
without the return, it works fine and prints out the string returned from 'hashit.pl' which is a perl script/program (i'm always confused about the difference).
why can't i return a variable?
do i need to return a buffered output stream? what's the best way?
all help is appreciated.
[still a greenhorn ]
jay
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay,
The Thread.start() method doesn't return anything, you can't do output=errorGrabber.start(). If you want to get data from your thread, then I would wait for it to finish and get it from the class. Here's something that "might" work and is quick-and-dirty.

It's quick, because it should work with minimal changes to your logic.
Cheers,
-Peter
 
Jay X Brown
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the suggestion peter but it didn't work. got a null result. i had actually already tried it, i should have said that.
also interesting is that it adds two nulls together for the response.
the latest code i tried:

i also tried adding this line:
outputGrabber.returner(proc.getInputStream());
(i modified the returner method in streamgrabber to accept inputstream as a parameter.)
gave me this response:

running it a second time gave this:

what's going on with the nulls? and...
what should i try next?
jay
[This message has been edited by Jay Brown (edited March 30, 2001).]
[This message has been edited by Jay Brown (edited March 30, 2001).]
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay,
The multiple nulls are coming from the static public String hashout = "";
1. Take out the static.
2. You don't need to initialize it to "".
-Peter
 
Jay X Brown
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok. thanks for that.
but why am i getting nulls? if not the 'quick fix', what's the other route?
right now i'm ramping up on pipedoutputstream and pipedinputstream. is this the right way to go?
thanks again.
jay
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay,
Send me your entire program including the hash.pl script. I'll test it on my side. Also tell me what version of the JDK you're using and on what platform.
-Peter
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay,
Here's the solution to your problem. You almost had it. You needed to capture the line information inside the while(). The loop breaks when br.readLine() returns null which gets assigned to line. When you did hashout=hashout+line; You're just concatenating the null literal value with itself.

I made some slight improvements to your program. See if you can figure out why.
Cheers!
-Peter
[This message has been edited by Peter Tran (edited April 03, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic