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 8656071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:11:20+00:00 2026-06-12T15:11:20+00:00

I have a shell script run.sh which is executing a jar file. #!/bin/bash $JAVA_HOME/bin/java

  • 0

I have a shell script run.sh which is executing a jar file.

#!/bin/bash
"$JAVA_HOME"/bin/java -jar test.jar $1 $2 $3

After doing all the process in java I need to execute a command. So my java method calls a
shell script by passing it some arguments.

public static void Test(String Arg1, int Arg2, int Arg3, String Arg4) throws IOException, InterruptedException {

            File currentLocation = new File(Test.class.getProtectionDomain().getCodeSource().getLocation().getPath());

            String executeShellScript = currentLocation.getParentFile().toString() + "/out.sh";

           //SOME LOGIC

            ProcessBuilder pb = new ProcessBuilder("/bin/sh",executeShellScript,arg1, arg2, arg3, arg4);
            pb.redirectErrorStream(true);

            Process p = pb.start();
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }

        }

And in my out.sh I take in the arguments and execute a command.

#!/bin/bash

IMAGE=$1
ROW=$2
COLUMN=$3
DESTINATION=$4
echo $IMAGE

I was wondering if I could execute and process the output of my jar from the same script (run.sh) by getting all the arguments?

  • 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-06-12T15:11:21+00:00Added an answer on June 12, 2026 at 3:11 pm

    You can redirect the output of your jar in a file (>out.txt after your $3 in run.sh) and process that file in run.sh. or you can pipe (|) the output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I have a shell script that calls a java jar file and runs an
I have a shell script testShell.sh which uses getopts as below: #!/bin/bash while getopts
Hi I have a shell script which should run based on the return of
I have a shell script, which is run under a opensuse linux, that starts
Have a shell script that reads the files in a particular directory. #!/bin/bash for
I have a shell script which I want to run without using the sh
i have unix shell script which is need to be run like below test_sh
I have a shell script which works perfectly if I run it in the
I want to run a power shell script which can run a exe file

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.