LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


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

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


Hi,

I have create a shell script with a function.



Code:
 #!/bin/bash

echo "Test shell script"

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

checkfunction

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


NOTE:
When i invoke the above shell script from java using the code
Code:
Runtime.getRuntime().exec(filename.sh) ;

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.


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

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Do you really have space as first character in your script?
Code:
 #!/bin/bash
# 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.
 
  


Reply



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. ashish.ars@gmail.com Linux - Newbie 4 11-02-2011 03:08 AM
Running shell script in Ubuntu from a java program ashish.ars@gmail.com 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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:56 AM.

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