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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:23:22+00:00 2026-05-24T02:23:22+00:00

I need to execute a .exe file from a function in one of the

  • 0

I need to execute a .exe file from a function in one of the packages I have in my java project. now the working directory is the root directory of the project for java but the .exe file in sub-directories of my project. here is how the project is organized:

ROOT_DIR
|.......->com
|         |......->somepackage
|                 |.........->callerClass.java
|
|.......->resource
         |........->external.exe

Initially I tried to run the .exe file directly through:

String command = "resources\\external.exe  -i input -o putpot";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);

but the problem is external .exe needs to access some files in it’s own directory and keeps thinking root directory is its directory. I even tried to use .bat file to solve the problem but the same issue rises:

Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "resources\\helper.bat"});

and the .bat file is in the same directory as the .exe file but the same issue happens. here is the content of the .bat file:

@echo off
echo starting process...

external.exe -i input -o output

pause

even if I move .bat file to root and fix its content the problem does not go away. plz plz plz help

  • 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-24T02:23:23+00:00Added an answer on May 24, 2026 at 2:23 am

    To implement this you can use the ProcessBuilder class, here’s how it would look like:

    File pathToExecutable = new File( "resources/external.exe" );
    ProcessBuilder builder = new ProcessBuilder( pathToExecutable.getAbsolutePath(), "-i", "input", "-o", "output");
    builder.directory( new File( "resources" ).getAbsoluteFile() ); // this is where you set the root folder for the executable to run with
    builder.redirectErrorStream(true);
    Process process =  builder.start();
    
    Scanner s = new Scanner(process.getInputStream());
    StringBuilder text = new StringBuilder();
    while (s.hasNextLine()) {
      text.append(s.nextLine());
      text.append("\n");
    }
    s.close();
    
    int result = process.waitFor();
    
    System.out.printf( "Process exited with result %d and output %s%n", result, text );
    

    It’s quite a bunch of code, but gives you even more control on how the process is going to be run.

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

Sidebar

Related Questions

I need to execute MDX query from command line (MS AS 2005). I have
I have been using Process.Start to launch executables (.exe) files. Now I need to
i need to execute a .lnk file in java (lnk file that points at
guys. In my program, i need to execute a kmlsample.exe in CMD, right now,
I want to execute a external .exe program from within java. The .exe is
i have searched and read about issues with psexec.exe from sysinternals not working properly
I have two .exe file and 3 windows batch files and i need to
I need to execute a directory copy upon a user action, but the directories
I need to execute a http web request from Plesk's Task Scheduler (using shared
I need to execute a PowerShell script from within C#. The script needs commandline

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.