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.

Mehdi
  • 3,795
  • 3
  • 36
  • 65
  • you are right but I need also to elimibate the last part "java.exe" – Mehdi Feb 18 '16 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 – Mehdi Feb 18 '16 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 – Mehdi Feb 18 '16 at 13:26

1 Answers1

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:\>
riteshtch
  • 8,629
  • 4
  • 25
  • 38