Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5846797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:37:39+00:00 2026-05-22T12:37:39+00:00

Unix gurus! I have a Java program which passes some parameters to a Servlet

  • 0

Unix gurus!

I have a Java program which passes some parameters to a Servlet. The Servlet enters the info into a DB and returns back the ID of a row created back to the java program that calls it. The Java program is run in a Unix shell script, which later goes on to call another java program Java Program_2 (say).

My issue is this – I need to pass the ID we get from Java Program as a parameter to Java Program_2 in that same shell script. ARe there any best practice for this?

Things i am working with so far –

1) Make the java program return an exit code with System.exit(). 2 questions with this – How do i catch the exit code in a variable in the shell? Is this the right way to do it? Exit code is actually meant for returning the success parameter of the program…

2) Write the output in a file java Java_Program >opt.txt. If I do this, then how do I read the contents of opt.txt in a shell variable again?

Thanks a lot!

Edit: I should have mentioned this before actually… the programs are in different machines. I ssh into the other machine using the script..and then run java program 2. Hence, I cannot pipe the two.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:37:40+00:00Added an answer on May 22, 2026 at 12:37 pm

    I would not recommend using the exit status to carry data, for the reasons you’ve stated. Catching the exit status depends on what shell you’re using, but in Bash, the special $? variable contains the exit status of the last process executed.

    Writing data to stdout is far more idiomatic. In Bash, you capture it as follows:

    output=$(java Java_Program)
    

    or:

    output=`java Java_Program`
    

    (You will often hear arguments that the first syntax is to be preferred.)

    You can then feed this to stdin of your next process with:

    echo $output > java Java_Program_2
    

    More simply, you can simply pipe your processes together:

    java Java_Program | java Java_Program_2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help from the shell-script gurus out there. I have a .txt
I'm writing some unix-style Ruby scripts that take option flags. Normally, I write a
I am trying to port some C++ code from Windows to Solaris(Unix). There are
I have two xsl file each for different type of machines for various unix
Unix.....>>netstat -al | grep 8787 (will see packets on port 8787)
UNIX file-locking is dead-easy: The operating system assumes that you know what you are
Unix has \n, Mac was \r but is now \n and DOS/Win32 is \r\n.
UNIX timestamp always in GMT? I tried to run php function time() and when
Unix System programming to be precise.
I have learned to compile my own source over the years but always left

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.