Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call Java program main method from shell script  RSS feed

 
Rama Lakshmi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai pals,

I have small java prohram.i want call this program from shell script.so how to create a shell script which can call the java program.and hoe to specify the path of java programme in the shell script.

thanks in advance

--Regdars
Ramalakshmi
 
madhup narain
Ranch Hand
Posts: 148
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey
Try the Runtime Class.

Process p = Runtime.getRuntime().exec(cmdline);
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly. you want to execute the java program from the command prompt.

Just use java <fullyQualifiedClassName>
 
Rama Lakshmi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai madhup narain ,
Thank Q for u r quick reply.I don't anything regarding these shell script.
As u given some code,please guide how to write that shell script and how it should be saved i.e the extension i should giveand how should i run.

Suppose my java file is at location c:\javatest\test.java how my script identifies this path.

please guide in these points

---Regads
Ramalakshmi
 
Casper Maxwell
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know your exact aim so i wanted to show one more approach if your problem does not require a shell script strictly.

You can invoke Java programs from C programs using JNI as described below:

http://java.sun.com/docs/books/jni/html/invoke.html
 
Rama Lakshmi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai guys,

My problem solved.Thank Q for u r quick responce and help.

--Regards
Ramalakshmi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!