2

Suppose I set the Path inside Windows System Variable the following :

c:\path\to\java\bin

and my app is java.exe under the above path.

I'm looking for a way to get the path "c:\path\to\java\bin" by using windows command prompt.

3
  • you are right but I need also to elimibate the last part "java.exe" Commented Feb 18, 2016 at 13:00
  • for %i in (java.exe) do @echo. %~$PATH:i: -> how to remove the java.exe from last part of the echo path from the output of this ? please give me one line code Commented Feb 18, 2016 at 13:23
  • I also found the solution bur I can developed the above code and wrap into this : SET _test=123456789abcdef0 SET _result=%_test:~0,-7% ECHO %_result% =123456789 Commented Feb 18, 2016 at 13:26

1 Answer 1

0

I'm no Windows nor a powershell expert, but some googling gave me Linux functionality of which and sed in powershell ..

PS H:\> where.exe java C:\JDK\1.6.0.31\bin\java.exe C:\JDK64\1.8.0.45\bin\java.exe C:\JDK64\1.6.0.31.1\bin\java.exe C:\JDK64\1.7.0.79\bin\java.exe C:\Windows\System32\java.exe PS H:\> where.exe java | %{$_ -replace "[a-zA-Z0-9]+\.exe", ""} C:\JDK\1.6.0.31\bin\ C:\JDK64\1.8.0.45\bin\ C:\JDK64\1.6.0.31.1\bin\ C:\JDK64\1.7.0.79\bin\ C:\Windows\System32\ PS H:\> 
Sign up to request clarification or add additional context in comments.

1 Comment

just remove java.exe from this command -> for %i in (java.exe) do @echo.%~$PATH:i

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.