• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java to Shell script

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to send String/boolean value from java program to Shell script(ksh) ?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? Where's your code?
 
Winston Gutkowski
Bartender
Pie
Posts: 10273
60
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10273
60
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
result = "`java -cp . Trail`" (note the backward quotes - called 'graves')


gives result: command not found
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try one of these:
result = `java -cp . Trail `

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

 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be a space between if and [
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic