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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:03:24+00:00 2026-05-13T10:03:24+00:00

is there a way to add a specific directory to the Windows systemvariable %PATH%?

  • 0

is there a way to add a specific directory to the Windows systemvariable %PATH%?
This doesn’t seem to work:

String[] cmd = { "cmd", "/c", "set", "PATH=\"%PATH%;c:\\test\"" };
Runtime.getRuntime().exec( cmd );

c:\test\ doesn’t appear in System.getenv(“PATH”); or in the output of

String[] cmd = { "cmd", "/c", "echo", "%PATH%" };
Runtime.getRuntime().exec( cmd );

What I need is to modify the %PATH%-variable for the current Java-Process under Windows. The reason is, that I need to load some native dll-files which cross-reference each other. So I’d like to add the application-path to the Windows environment.

The next thing I tried was a small JNI-Wrapper for the C-Function “putenv” which looks like this:

JNIEXPORT void JNICALL Java_com_splitscreen_AppletTest_PutEnv_putEnv
  (JNIEnv *env, jobject jobj, jstring val) {

    jboolean iscopy;

    const char *mvalue = (*env)->GetStringUTFChars(
                env, val, &iscopy);

    putenv(mvalue);
}

This is how I call it:

final String curPath = System.getenv( "PATH" );
final PutEnv pe = new PutEnv();
pe.putEnv( "PATH=" + curPath + ";c:\test" );

final String newPath = System.getenv( "PATH" );
System.out.println( newPath );

But the pathes are equal. I’m not sure whether the Map of the Java-System-Environment isn’t updated or whether putenv didn’t work. Is there a way to check this?

  • 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-13T10:03:24+00:00Added an answer on May 13, 2026 at 10:03 am

    The reason this doesn’t work is that the two exec() invocations start two different shells; the one you set the path in isn’t the one you check it in.

    It’s difficult to change the permanent, systemwide path setting. But you can change the path for the duration of the invocation of one or more programs that you need it for.

    Specifically, the thing to do is to write yourself a batch file (.CMD or .BAT, as you please), set the PATH near the beginning, follow that with whatever DOS/Windows commands you’d like executed with that path, and then exec() that script file.


    Updating the PATH for the current Java process seems pretty pointless. Java, once running, doesn’t care about the path. Or are you running some library code that does?

    If you are running DOS/Windows commands from Java using exec(), the above trick will work.


    Update: OK, you have library code that for reasons of its own wants the PATH set just so, and you want to give it what it wants.

    What I would consider here is to fire up a new JVM. You can use exec(cmd, envp) to start up a new Java application (“yourself,” in a pinch) with a custom set of environment variables in envp. Just copy the ones that are already there and manipulate the contents of PATH, if any.

    The standard way to start up a new Java app is to create a new ClassLoader, and there are various descriptions on how to accomplish that. But I’m not sure you can use that procedure to come up with a new environment – so exec-ing the JVM may not only be simpler, but possibly the only way.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.