Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason this doesn't work is that the two <code>exec()</code> invocations start two different shells; the one you set the path in isn't the one you check it in.</p> <p>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.</p> <p>Specifically, the thing to do is to write yourself a batch file (<code>.CMD</code> or <code>.BAT</code>, as you please), set the <code>PATH</code> near the beginning, follow that with whatever DOS/Windows commands you'd like executed with that path, and then <code>exec()</code> that script file.</p> <hr> <p>Updating the PATH for the current <em>Java</em> process seems pretty pointless. Java, once running, doesn't care about the path. Or are you running some library code that does?</p> <p>If you are running DOS/Windows commands from Java using <code>exec()</code>, the above trick will work.</p> <hr> <p><strong>Update:</strong> 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.</p> <p>What I would consider here is to fire up a new JVM. You can use <code>exec(cmd, envp)</code> to start up a new Java application ("yourself," in a pinch) with a custom set of environment variables in <code>envp</code>. Just copy the ones that are already there and manipulate the contents of <code>PATH</code>, if any.</p> <p>The standard way to start up a new Java app is to create a new <code>ClassLoader</code>, 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 <code>exec</code>-ing the JVM may not only be simpler, but possibly the only way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload