Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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:

  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:

  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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .