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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:46:46+00:00 2026-05-21T15:46:46+00:00

I call a class which is located somewhere in a jar file (using java

  • 0

I call a class which is located somewhere in a jar file (using java -classpath path/file.jar classname) within my java code.

This work well but only if the command is well formed. If I make a mistake the getRuntime().exect(command) just doesn’t say anything. Bellow I have the working command invocation. I would like to get the error message when the command doesn’t work. If I make a mistake in a cmd (windows) I get a proper error and I can fix it. But not within my java application.

I left a ‘if(input.ready())’ since if I don’t the program freezes when the command line is incorrect. This happens when executing ‘input.readLine()’.

        // Execute a command with an argument that contains a space
        String[] genKOSCommand = new String[] {
                "java",
                "-classpath",
                Config.XDSI_TEST_KIT_HOME + "/xdsitest/lib/xdsitest.jar;"
                        + Config.XDSI_TEST_KIT_HOME + "/xdsitest/classes",
                "ca.etsmtl.ihe.xdsitest.docsource.SimplePublisher", "-k",
                "C:/Softmedical/Viewer_Test/xdsi-testkit-2.0.4/xdsihome/usr/data/image14.dcm" };

        Process child = Runtime.getRuntime().exec(genKOSCommand);

        BufferedReader input = new BufferedReader(new InputStreamReader(
                child.getInputStream()), 13107200);

        String line = null;

        if (input.ready()) {
            while ((line = input.readLine()) != null) {
                System.out.println(line);
            }

            try {
                child.waitFor();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

Have any advice on how to get an error from the executed command?

Thank you

  • 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-21T15:46:47+00:00Added an answer on May 21, 2026 at 3:46 pm

    By using getErrorStream:

    BufferedReader errinput = new BufferedReader(new InputStreamReader(
                    child.getErrorStream()));
    

    When processing the input from the different streams, it is better to do it in a different thread (since those calls (readLine etc.) are blocking calls.

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

Sidebar

Related Questions

What is the point of having a dynamic class on which you can call
I have a template class that I serialize (call it C), for which I
What does it mean to call a class like this: class Example { public:
As title says, how do I call a java class method from a jsp,
I want to inherit from a class which is located in a WCF Service.
Say you have a custom class call it Foo. When you then have an
So here is the deal. I want to call a class and pass a
I want a pure virtual parent class to call a child implementation of a
I cant call protected function in my base class. Why? It looks something like
What method do I call to get the name of a class?

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.