0

I use this to set the path, but when i am run this batch more than one time same path will set for several times, i want to put a restriction like if a particular path is not set before then set this path. How to do this, Please give some idea .

path="C:\Program Files\Java\jdk1.7.0_21\bin";%path%

Sanojit
  • 57
  • 10
  • This might help: [Batch file: Find if substring is in string (not in a file)](http://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file) – Gilad Foyer Dec 10 '14 at 08:59

3 Answers3

0

try

command -v java 

it should tell you if you already have java in your path.
Then you can use that appropriately with an if statement to set your path.

pierroz
  • 7,653
  • 9
  • 48
  • 60
0
set myPath="C:\Program Files\Java\jdk1.7.0_21\bin"
For /F "Delims=" %%I In ('echo %PATH% ^| find /C /I "%myPath%"') Do set pathExists=%%I 2>Nul
If %pathExists%==0 (set PATH=%myPath%;%PATH%)
Gilad Foyer
  • 1,143
  • 1
  • 11
  • 12
0
where /q java.exe || path="C:\Program Files\Java\jdk1.7.0_21\bin";%path%

Where.exe will search the path for a filename, or set a nonzero ERRORLEVEL if the exe isn't in the path. This line will run your PATH command only if java.exe isn't found in the path

Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54