jtulach commented on code in PR #8756:
URL: https://github.com/apache/netbeans/pull/8756#discussion_r2347152969


##########
nb/ide.launcher/windows/nblauncher.cpp:
##########
@@ -114,6 +128,18 @@ int NbLauncher::start(int argc, char *argv[]) {
     if (!userDir.empty()) {
         newArgs.add(ARG_NAME_USER_DIR);
         newArgs.add(userDir.c_str());
+        if (!skipUserDir) {
+            string toSet = ENV_NETBEANS_USERDIR;
+            toSet = toSet + "=" + userDir;
+            putenv(toSet.c_str());
+
+            const char* path = getenv("PATH");
+            if (path != NULL) {
+                string setPath = "PATH=";
+                setPath = setPath + path + ";" + baseDir + "\\bin\\";
+                putenv(setPath.c_str());

Review Comment:
   I tested these changes with following program:
   ```java
   package execenv;
   
   public class ExecEnv {
       public static void main(String[] args) throws Exception {
           System.out.println("Env: " + System.getenv("PATH"));
           var p = new ProcessBuilder("netbeans", "S:\\readme.txt").start();
           var r = p.waitFor();
           System.out.println("Res: " + r);
       }
   }
   ```
   when executed on NetBeans 27 it fails with:
   ```
   run:
   Env: C:\Program 
Files\OpenSSH\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
 Files\Git\cmd;C:\Users\jst\AppData\Local\nvm;C:\nvm4w\nodejs;C:\Program Files 
(x86)\Windows Kits\10\Windows Performance 
Toolkit\;C:\Users\jst\.cargo\bin;C:\Users\jst\AppData\Local\Microsoft\WindowsApps;C:\Users\jst\AppData\Local\nvm;C:\nvm4w\nodejs;C:\Program
 
Files\Git\bin;S:\windows\bin;S:\windows\bin\graalvm-community-openjdk-24.0.1+9.1\bin\;S:\windows\bin\sbt-1.7.2\bin\;
   Exception in thread "main" java.io.IOException: Cannot run program 
"netbeans": CreateProcess error=2, The system cannot find the file specified
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1044)
        at execenv.ExecEnv.main(ExecEnv.java:6)
   Caused by: java.io.IOException: CreateProcess error=2, The system cannot 
find the file specified
        at java.base/java.lang.ProcessImpl.create(Native Method)
        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:485)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:146)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1076)
        ... 2 more
   C:\Users\jst\AppData\Local\NetBeans\Cache\27\executor-snippets\run.xml:111: 
The following error occurred while executing this line:
   C:\Users\jst\AppData\Local\NetBeans\Cache\27\executor-snippets\run.xml:68: 
Java returned: 1
   BUILD FAILED (total time: 1 second)
   ```
   With changes in this PR it **properly opens the file** in the IDE executing 
the script.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to