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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:12:42+00:00 2026-06-02T00:12:42+00:00

I’m working on a Java program that calls several Shell scripts within JUnit tests

  • 0

I’m working on a Java program that calls several Shell scripts within JUnit tests (hence no output except .’s and E’s) that manipulate files and SQL tables and then compares data in said tables to their expected values. Everything works in theory, however I’m encountering a strage bug where one type of test works as expected while the other type fails after a ten minute time-out. I’ve isolated the problem to be one of the Shell scripts, however I did not write this script and I’m unable to change it in any way. The best way I can troubleshoot this is saving the output of the script in question, which comes from a series of echo calls. Is there a somewhat straightforward/reliable way to save echo output? I’ve googled a bit but nothing’s come up. I haven’t tried to store the output yet so I don’t have an attempt to show you, but the code I’ve already written that may be relevant is:

//Currently using BufferedWriter, File, FileWriter, IOException, and Writer
import java.io.*;

//Method to write to a log file
public void record(String input) throws IOException {
  writer = new BufferedWriter(new FileWriter(file,true));
  writer.write(input + "\n");
  writer.close();
}

Runtime rt = Runtime.getRuntime();

//Several of these since a lot of file manipulation/script running occurs
process = rt.exec("./shell.sh");
process.waitFor();

In another question I asked, someone recommended not using Runtime.exec() for several reasons. While I realize the advantages to not using exec(), I need to for this version of the program.

The tl;dr question: Can my Java program easily run shell scripts as well as save their echo’d output? If not, is there a tail -f equivalent for reading the output?

  • 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-02T00:12:44+00:00Added an answer on June 2, 2026 at 12:12 am

    To do this as painlessly as possible you should really use Asyncronous reading and writing of the output of the external process. That is what is probably blocking and causing the time outs, is the way the script is echoing it’s contents back, and they are not being consumed.

    I posted an answer to this exact same question a while ago, this works in all situations when reading from external processes, and is the why of why not to use Process.exec() anymore and use ProcessBuilder.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.