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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:32:49+00:00 2026-05-19T05:32:49+00:00

Is it possible to open the command prompt (and I guess any other terminal

  • 0

Is it possible to open the command prompt (and I guess any other terminal for other systems), and execute commands in the newly opened window?

Currently what I have is this:

Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"cmd.exe","/c","start"});

I’ve tried adding the next command after the “start”, I’ve tried running another rt.exec containing my command, but I can’t find a way to make it work.

If it matters, I’m trying to run a command similar to this:

java -flag -flag -cp terminal-based-program.jar

EDIT Unfortunately I have had some strange findings. I’ve been able to successfully launch the command prompt and pass a command using this:

rt.exec("cmd.exe /c start command");

However, it only seems to work with one command. Because, if I try to use the command separator like this, “cmd.exe /c start command&command2”, the second command is passed through the background (the way it would if I just used rt.exec(“command2”);). Now the problem here is, I realized that I need to change the directory the command prompt is running in, because if I just use the full path to the jar file, the jar file incorrectly reads the data from the command prompt’s active directory, not the jar’s directory which contains its resources.

  • 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-19T05:32:51+00:00Added an answer on May 19, 2026 at 5:32 am

    I know that people recommend staying away from rt.exec(String), but this works, and I don’t know how to change it into the array version.

    rt.exec("cmd.exe /c cd \""+new_dir+"\" & start cmd.exe /k \"java -flag -flag -cp terminal-based-program.jar\"");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Open a new prompt/terminal window from Java Is it possible to open
Is it possible to open a terminal window with 3 tabs. Each tab should
From the command prompt it's possible to run for example open http://www.example.com and have
Possible Duplicate: Entity Framework: There is already an open DataReader associated with this Command
Possible Duplicate: Open child browser window from child window I have a list of
I am using open( my $command_out, -|, $command_string ) to execute a command and
Possible Duplicate: Auto-open NERDTree in “EVERY” tab Is there a way to automatically execute
Is it possible via the command line to get the current open tab url
If I were to open a file with Vim from the command prompt (eg:
Is it possible to open a command line from Java application, meaning, I have

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.