Java return a value to Unix variable

Discussion in 'Java' started by Sam Palanivel, Jun 24, 2004.

  1. 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
     
    Sam Palanivel, Jun 24, 2004
    #1
    1. Advertising

  2. Sam Palanivel

    Yu SONG Guest

    Sam Palanivel wrote:
    > 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/
    _______________________________________________________
     
    Yu SONG, Jun 25, 2004
    #2
    1. Advertising

  3. Sam Palanivel

    iksrazal Guest

    "Sam Palanivel" <> wrote in message news:<cbf920$sse$>...
    > 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
     
    iksrazal, Jun 25, 2004
    #3
  4. "Sam Palanivel" <> wrote in
    news:cbf920$sse$:

    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------
     
    Tris Orendorff, Jun 25, 2004
    #4
  5. Sam Palanivel

    Guest

    Tris Orendorff <> wrote in message news:<Xns9513841AF99DARepublicPicturesLtd@216.221.81.119>...
    > "Sam Palanivel" <> wrote in
    > news:cbf920$sse$:
    >
    > 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!


    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.

    --
    http://www.sun.com/
    http://www.usc.edu/dept/MSA/quran/
    http://www.google.ca/
    http://www.microsoft.com/windows/ie/default.mspx
     
    , Jun 30, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    2,990
  2. Replies:
    12
    Views:
    1,672
    Dave Thompson
    Jan 10, 2005
  3. Replies:
    18
    Views:
    638
    Dave Thompson
    Jan 10, 2005
  4. Greenhorn
    Replies:
    15
    Views:
    849
    Keith Thompson
    Mar 6, 2005
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    293
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page