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

  • Home
  • SEARCH
  • 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 6975637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:23:38+00:00 2026-05-27T17:23:38+00:00

I have a java program which is supposed to launch a shell script. The

  • 0

I have a java program which is supposed to launch a shell script. The script contains 6 tasks which are to be executed in sequence. The java program launches the script and it starts(as I see the logs). But after 10-15 seconds, the execution stops, even before the first task in the shell script is completed. The strange thing is that the script runs fine when I launch it in terminal. To avoid risking the program to hang while the script is being executed, I launch it in a separate thread. What might be a probable reason?

Java code –

try {   
            log.info("run cmd - "+optionsRun);

            String[] cmdLine = (String[]) optionsRun.toArray(new     String[optionsRun.size()]);

            Process process = Runtime.getRuntime().exec(cmdLine);
            log.info("end run cmd " + this.getScriptPath());

//          
//          BufferedWriter writer = new BufferedWriter(new     OutputStreamWriter(process.getOutputStream()));
//          writer.write("mypwd");
//          writer.flush();
//          writer.close();


            InputStream is = process.getErrorStream();
            String error = inputStreamToStringValue(is);
            log.trace("Eventual error was : " + error);

            InputStream os = process.getInputStream();
        String output = inputStreamToStringValue(os);
            log.info("Eventual output was : " + output);

            if (error!=null & error.length()>0) {
                throw new ActionProcessingException("An error occurred when     running the script :'"+this.getScriptPath()+"' with following error message : "+error);    
            }else {
                log.info("Script run ended successfully.");
            }

And the shell script looks this way –

#!/bin/sh
# ./publish <path-to-publish-home-folder> <workspace_id> <start_date> <end_date>
# ./publish <path-to-publish-home-folder> 100011 2010-01-06-12:00:00-CET     2012-01-14-19:00:00-CET

rm -f $1/publish.log
echo 'Start publish' >> $1/publish.log
echo $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 >> $1/publish.log

# lancement de l'export RDF du domaine
cd $1/1-export-domain
echo "Starting export domain with the command - ./export.sh $2" >> $1/publish.log
./export.sh $2

# lancement de l'export des translations du domaine
cd $1/2-export-trans
echo "Starting export domain(translated) with the command - ./export.sh $2" >>         $1/publish.log
./export.sh $2
.....
.....
a couple of more steps like 1 and 2
....

Thanks in advance,

  • 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-27T17:23:39+00:00Added an answer on May 27, 2026 at 5:23 pm

    I’m not sure, but I’ll recommend two links that might help you figure it out.

    The first is a very old one about Runtime.exec():

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

    The second is about ProcessBuilder, the new class intended to replace Runtime.exec():

    http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html

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

Sidebar

Related Questions

I have a Java program which is supposed to remove all non-letter characters from
I have a tiny little program in Java which supposed to display 2 spheres.
I have a Java program in which an action is initiated which loops through
I currently have a small Java program which I would like to run both
I now have a running Java program which only lacks of the final step,that
How to write a java program which will tell me whether I have internet
I have a program which i have myself written in java, but I want
I have two strings in a java program, which I want to mix in
We have a Perl program to validate XML which is invoked from a Java
I have a Java-program which communicates with a C++ program using a socket on

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.