Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to do this simple thing on windows but it always fail and i think that the cause is that it's not looking in the PATH variable, how should i do?

IF EXIST lessc.cmd (
    lessc --yui-compress bootstrap.less > ../css/bootstrap.min.css
) ELSE (
    echo Error: lessc not found. Install Node.js then: npm install -g less
)
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Your Windows version probably has where.exe:

where /q lessc || (
    echo Errrrror.
    goto :eof
)

lessc --yui-compress bootstrap.less > ../css/bootstrap.min.css

The || operator works like in Linux sh; its opposite is &&.


For older versions:

:havecomm
  set "comm=%~$PATH:1"
  goto :eof

Whenever you call it with call :havecomm lessc, it will set %comm% to its full path, or empty if not found.

If you don't know the exact extension and want to check all possibilities, the longer version will work:

:havecomm
  set comm=
  if not "%~$PATH:1"=="" (
    set "comm=%~$PATH:1"
  ) else (
    for %%e in (%PATHEXT%) do (
      for %%i in (%1%%e) do (
        if not "%%~$PATH:i"=="" (
          set "comm=%%~$PATH:i"
          goto :eof
  ))))
  goto :eof
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.