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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:08:41+00:00 2026-06-13T22:08:41+00:00

I need to launch another Java program at runtime, this is my code try

  • 0

I need to launch another Java program at runtime, this is my code

  try {
                                 String cmd2 = "java -jar c:\\test\\deploy\\framework_e_app.jar";

                                 Process p = Runtime.getRuntime().exec(cmd2);  
                                 BufferedReader in = new BufferedReader(  
                                                     new InputStreamReader(p.getInputStream()));  
                                 String line = null;  
                                 while ((line = in.readLine()) != null) {  
                                         System.out.print("<STDOUT>");
                                     System.out.print(line);
                                     System.out.println("</STDOUT>");
                                 }  

                                 InputStream stderr = p.getErrorStream();
                                 InputStreamReader isr = new InputStreamReader(stderr);
                                 BufferedReader br = new BufferedReader(isr);
                                 String line2 = null;
                                 System.out.print("<STDERROR>");
                                 while ( (line2 = br.readLine()) != null)
                                     System.out.print(line2);
                                 System.out.println("</STDERROR>");

                         } catch (IOException e) {  
                             e.printStackTrace();  
                         }

This is the only way i got it working, but it is annoying because it search configuration files in the current path.

I tried using this as cmd2:

String[] cmd2 = new String[4];
cmd2[0] = "cmd";
cmd2[1] = "/C";
cmd2[2] = "cd test\\deploy";
cmd2[3] = "java -jar framework_e_app.jar";

I couldn’t get working the directory change. What’s the right syntax? (Im in a Windows environment, obviously).

  • 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-13T22:08:42+00:00Added an answer on June 13, 2026 at 10:08 pm

    the cd does not stick. each command is executed in a different process. use a form of exec that has the working directory like http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec%28java.lang.String%5B%5D,%20java.lang.String%5B%5D,%20java.io.File%29

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

Sidebar

Related Questions

In my .net web application, I need to launch another program as a new
I would like to launch fancybox from another function. I need this trigger after
I have a main program written in C, i need it to launch another
I need to launch call task in my wp7 app. once i launch this
I'm doing a Java Record/Replay tool and I need to launch Java applications from
I have an application (A) that needs to launch another application (B). I need
I need to launch 'TextMate' from an App, and I used the following code.
I'm creating a C# program and I need to control another application. I found
I have a long running process and I need it to launch another process
I've found a need to launch a WPF application from inside a c# program.

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.