Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 12-06-2012, 11:08 PM   #1
LQ Newbie
Registered: Aug 2012
Posts: 3

Rep: Reputation: Disabled
Problem while Invoke Shell Script function from Java Program


I have create a shell script with a function.


echo "Test shell script"

function checkfunction() 
  echo "hey!  shell script function called"


when i execute the above program in local/terminal. i got the output:
Test shell script
hey! shell script function called

When i invoke the above shell script from java using the code
Runtime.getRuntime().exec( ;

i got the output:
Test shell script

Here the problem is, the function in shell script is not invoked.

whether i have to export the functions?
Please Suggest me, how to solve this problem.

Nanthagopal A
Old 12-07-2012, 03:07 PM   #2
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
Do you really have space as first character in your script?
# rest of code
It shouldn't be there. With space at the beggining bash is not invoked and probably another shell execute rest of your script, which have different syntax, for example "dash" no need "function" word to define function. You should check exit status (by waitFor() function) and grab standard error stream to see if there is any errors.

Last edited by eSelix; 12-07-2012 at 03:09 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Only part of shell script executed from Java program. Linux - Newbie 4 11-02-2011 03:08 AM
Running shell script in Ubuntu from a java program Ubuntu 4 10-28-2011 05:47 AM
How can I call a C program in a Shell Script from Java habibur Programming 3 10-24-2009 02:09 AM
booting to a fullscreen java program with a shell script sebastian.raghe Linux - Newbie 3 05-19-2005 02:42 AM
Creating a shell script to run Java program paultaylor Programming 7 11-12-2004 03:11 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration