0

I would like to get the path to the working directory of a specific process (for example for the PID of the process). I am Not Talking about the working or current Directory of the process where my Java Code is running. Its a simple task with Linux, but for Windows i cant find a proper solution. Furthermore, it would be nice, if its a Command or a Framework for Java, because i will need the path in my Code. I am not looking for the path to the executable, also Not for a solution with wmic or process explorer. Already thanks for the help.

I already tried commands like tlist and wmic, but those solutions cant be utilize in my code. I am looking for a solution that i can use without special installations on Windows.

Enes
  • 33
  • 1
  • 4

1 Answers1

0

JNI and JNA provide means to call directly into native libraries from Java code, and it is feasible to use these to call out to Windows libraries.

There is a github project that appears to be close to the need: https://github.com/kohsuke/winp. Perhaps you can add the needed code and send up a pull request, or fork the project.

Note that any solution here is going to be windows-specific, meaning the application using it will not run on another platform. Given the nature of the question, that doesn't sound like it would ever be a concern.

ash
  • 4,867
  • 1
  • 23
  • 33
  • Thank you, i tried the project to get the Environment Variables, but it seems that there is no way to get the CD Variable. Still thank you! – Enes Apr 16 '19 at 14:41
  • Ahh ouch - looks like there may not be a simple API call for this: https://stackoverflow.com/questions/2967650/is-it-possible-to-determine-the-working-directory-of-another-process – ash Apr 17 '19 at 19:59