Java return a value to Unix variable

S

Sam Palanivel

Hi,

I have java program which does all the processing and I need return value to
Unix variable.

Question: How can I return a value to Unix variable?

Thanks
Sam
 
Y

Yu SONG

Sam said:
Hi,

I have java program which does all the processing and I need return value to
Unix variable.

Question: How can I return a value to Unix variable?

Do you want to "set" a variable in Unix or "get" a variable value from Unix?

Have a look at

"EXPORT" unix cmd

&

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperty(java.lang.String)


HTH


--
Song

/* E-mail.c */
#define User "Yu.Song"
#define Warwick "warwick.ac.uk"
int main() {
printf("Yu Song's E-mail: %s@%s", User, Warwick);
return 0;}

Further Info. : http://www.dcs.warwick.ac.uk/~esubbn/
_______________________________________________________
 
I

iksrazal

Sam Palanivel said:
Hi,

I have java program which does all the processing and I need return value to
Unix variable.

Question: How can I return a value to Unix variable?

Thanks
Sam

If you start a shell, and set a variable, the variable is only good
for the life of that shell. So with Runtime.exec(), you can execute
any command in the shell, but shell vars die when the command shell
dies /runtime exec finishes. Heres an example for 'whoami' on
solaris. Setting vars are shell specific.

Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("/usr/ucb/whoami");
BufferedReader out = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String output = "";
while((output = out.readLine()) != null)
{
System.out.println("ID --> " + output);
}

HTH

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal
 
T

Tris Orendorff

f> Hi,
I have java program which does all the processing and I need return
value to Unix variable.

Question: How can I return a value to Unix variable?

Hi,

Use the ` feature of most shells to run a program and use its standard output as input on a command line:

xxx=`java HelloWorldApp.class`
echo $xxx
Hello, World!

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d++ s+:- a+ C+ UL++++ P+ L+ E- W+ N++ o- K++ w+ O+ M !V PS+ PE Y+ PGP t+ !5 X- R- tv--- b++
DI++ D+ G++ e++ h---- r+++ y+++
------END GEEK CODE BLOCK------
 
M

mromarkhan

Tris Orendorff said:
f> Hi,

Hi,

Use the ` feature of most shells to run a program and use its standard output as input on a command line:

xxx=`java HelloWorldApp.class`
echo $xxx
Hello, World!

Peace.

<output>
$ xxx=`java me`
$ echo $xxx
Peace
$
</output>


Those quotes are backquotes, which are located near the number one
on my keyboard.

You can use this technique with other programs that output their
data to standard out, such as lynx. In addition, the pipe
operator may be used.
<code>
#!/usr/bin/ksh
tableCount=0
trCount=0
endtrCount=0
readData=0
no_reg_string="<td align=\"center\" bgcolor=\"#FFFFFF\" colspan=\"2\"><IMG"
tableElement="<table"
rowElement="<tr"
endrowElement="</tr"
raw_data=`lynx -source -dump http://weatheroffice.ec.gc.ca/forecast/city_e.html?yyz`
echo "content-type: text/html"
echo
tableThere=`echo "$raw_data" | grep "$no_reg_string"`
#<td align="center" bgcolor="#FFFFFF" colspan="2">
#<IMG src="/weathericons/16.gif" border="0"
#width="60" height="51" alt="Light Snow"></td>
#remove everything up to first >
#remove </td>
#surround with base tag
#backslash use to escape &gt;
no_left=${tableThere#*\>}
no_right=${no_left%\</td\>}
echo "<base href=\"http://weatheroffice.ec.gc.ca\">$no_right</base>"

</code>

<output>
content-type: text/html

<base href="http://weatheroffice.ec.gc.ca"><IMG src="/weathericons/31.gif" borde
r="0" width="60" height="51" alt="Mainly Clear"></base>
</output>


Have a good day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top