Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-13-2010, 11:46 PM
|
#1
|
|
LQ Newbie
Registered: Sep 2004
Location: Dharwad, India
Distribution: Mandrake
Posts: 3
Rep:
|
Java hangs even though shell script’s execution is completed
I'm trying to execute a script from within my java code. The execution of the script is over(it's pid is no more), but java is stuck on waitFor() method of the shell script process!. And yes, I'm reading output and error streams in 2 separate threads. Yes, they are being joined at the end(after waitFor()).
The aspect which makes this question relevant to this forum is, if I put the following line in the shell script(at the top), everything seems to work fine.
Code:
exec 3>&1 > /tmp/some_log 2>&1
And no, interestingly enough, the script doesn't generate any output!. Zero chars!. So putting exec statement there makes no sense!
But still, magically enough, putting exec statement in the script makes java work!. Why??
How can I avoid that illogical exec statement in the script?.
exec has any other functionality here, other than redirection?
|
|
|
|
08-14-2010, 10:43 PM
|
#2
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Dude - how are WE supposed to figure out what either your Java program or your shell script are supposed to be doing???
Yes, it's possible to call a shell script from a Java program. Easy, in fact!
Yes, generally, you should be able to see anything that's printed to stderr or stdout.
And yes, you should be able to redirect stderr and/or stdout to a file.
SUGGESTION:
1. Try reproducing the problem with a "simple-as-possible" test program
2. If, at that point, you still can't figure out, then post the COMPLETE contents of your (small!) test program and (even smaller!) script.
|
|
|
1 members found this post helpful.
|
08-15-2010, 02:20 AM
|
#3
|
|
LQ Newbie
Registered: Sep 2004
Location: Dharwad, India
Distribution: Mandrake
Posts: 3
Original Poster
Rep:
|
Quote:
Originally Posted by paulsm4
Dude - how are WE supposed to figure out what either your Java program or your shell script are supposed to be doing???
Yes, it's possible to call a shell script from a Java program. Easy, in fact!
Yes, generally, you should be able to see anything that's printed to stderr or stdout.
And yes, you should be able to redirect stderr and/or stdout to a file.
SUGGESTION:
1. Try reproducing the problem with a "simple-as-possible" test program
2. If, at that point, you still can't figure out, then post the COMPLETE contents of your (small!) test program and (even smaller!) script.
|
Thanks for your attention. I had a discussion here.
Posted the link for the benefit of others, if they ever face such a situation.
|
|
|
0 members found this post helpful.
|
08-15-2010, 01:34 PM
|
#4
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
pavanlimo -
You're just asking a bunch of vague questions and making a bunch of totally unwarranted guesses.
Not the best way to solve a problem, IMHO.
My suggestion remains: try to reproduce the problem with a minimal test case, then DETERMINE what the problem is. Don't GUESS.
PS:
While you're at it, you might want to look into "buffered I/O'.
Why it's a Good Thing.
And why it might lead to sometimes "unexpected" results.
Two clues:
1. "stdout" (stream 1) is buffered; "stderr" (stream 2) isn't.
Try writing to stderr instead of stdout in your program and see if you get different results.
2. When a program ends (*really* ends), all buffered output is flushed (unless, of course, it terminates abnormally)(which is probably not the case here).
In any case, try to THINK about what you're doing. Don't just arbitrarily throw stuff at the wall and jump to false conclusions
about what happens to stick.
IMHO .. PSM
|
|
|
|
08-16-2010, 01:14 PM
|
#5
|
|
LQ Newbie
Registered: Sep 2004
Location: Dharwad, India
Distribution: Mandrake
Posts: 3
Original Poster
Rep:
|
I don't think I'm "throwing stuff at the wall and jumping to false conclusions".
Nevertheless I thank you for your time and response. Appreciate it.
I had a good discussion with other guys, ultimately got a solution.
Please see the solution here.
Thanks.
Last edited by pavanlimo; 08-16-2010 at 01:15 PM.
|
|
|
|
08-16-2010, 03:49 PM
|
#6
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Hi, pavanlimo -
Thank you for the followup, and sorry if I was a bit hard on you
More important, I'm glad you're squared away
Sincerely .. PSM
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:46 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|