wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes Java to Shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Java to Shell script" Watch "Java to Shell script" New topic
Author

Java to Shell script

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
How to send String/boolean value from java program to Shell script(ksh) ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

What have you tried so far? Where's your code?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7549
    
  18

kri shan wrote:How to send String/boolean value from java program to Shell script(ksh) ?

System.out.println(String) is one.

Winston
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
trial.sh
---------


javac Trail.java

result = java -cp . Trail

if[ $result == "bye" ]; then
echo "correct"
else
echo "not correct"
fi


Trial.java
----------

public class Trail {
static String test = "bye";
public static void main(String args[]) {
System.out.println(test);
}
}

./trail.sh shows syntax error near unexpected token 'then'


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

At this point your question has nothing to do with Java. You're asking about the syntax of the bourne shell. Moving to Linux/Unix.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7549
    
  18

And FYI, the correct way to pull a result from stdout is:
result = "`java -cp . Trail`" (note the backward quotes - called 'graves')

Winston
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
result = "`java -cp . Trail`" (note the backward quotes - called 'graves')


gives result: command not found
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
Try one of these:
result = `java -cp . Trail `

Bash supoorts this syntax too:
result = $( java -cp . Trail )

Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

There should be a space between if and [


Thanks and Regards,
~Sujoy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java to Shell script
 
Similar Threads
FTP
Running a Java Class from a Unix Shell Script
Problem in Executing .exe file using Script
Scheduling Pls Help
running java program from a shell script