2013-12-11 1 views
2

У меня есть эта ANT задачу выполнить Sass в проекте Eclipse:В затмении, выполняющем Sass с задачей ANT. Зачем мне устанавливать «исполняемый файл» на «sass.bat» вместо «sass»?

<project basedir="." default="sass"> 
    <target name="sass"> 
     <apply dest="www/styles" executable="sass"> 
      <srcfile/> 
      <targetfile/> 
      <fileset dir="styles" includes="*.scss"/> 
      <mapper from="*.scss" to="*.css" type="glob"/> 
     </apply> 
    </target> 
</project> 

Это отлично работает в Ubuntu. В Windows 7 я должен установить исполняемый файл как sass.bat.

Это ошибка:

Buildfile: D:\my_workspace\my_project\build.xml 

sass: 

BUILD FAILED 
D:\my_workspace\my_project\build.xml:3: Execute failed: java.io.IOException: 
Cannot run program "sass" (in directory "D:\my_workspace\my_project"): 
CreateProcess error=2, The system cannot find the file specified 

Total time: 326 milliseconds 

И, дерзость и sass.bat может быть вызван из командной строки, так как папка Ruby/bin в системе PATH переменной.

Я не хочу распространять две версии этого файла для разных ОС.

Как я могу это решить?

ответ

4

Я решил, добавив условную переменную exec_file со значением sass.bat для ОС семейства Windows, и sass для другого.

<project basedir="." default="sass"> 
    <condition property="exec_file" value="sass.bat" else="sass" > 
     <os family="windows" /> 
    </condition> 

    <target name="sass"> 
     <apply dest="www/styles" executable="${exec_file}"> 
      <srcfile/> 
      <targetfile/> 
      <fileset dir="styles" includes="*.scss"/> 
      <mapper from="*.scss" to="*.css" type="glob"/> 
     </apply> 
    </target> 
</project> 
3

[не ответ, но слишком большой для комментариев]

оболочки Windows, понять, как расширить PATHEXT. Ant не интерпретирует - это только попытка .exe, а не других.

See comments for Windows Users

The task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. It is the latter Win32 function that defines the exact semantics of the call. In particular, if you do not put a file extension on the executable, only ".EXE" files are looked for, not ".COM", ".CMD" or other file types listed in the environment variable PATHEXT. That is only used by the shell.

Note that .bat files cannot in general by executed directly. One normally needs to execute the command shell executable cmd using the /c switch.

A common problem is not having the executable on the PATH. In case you get an error message Cannot run program "...":CreateProcess error=2. The system cannot find the path specified. have a look at your PATH variable. Just type the command directly on the command line and if Windows finds it, Ant should do it too. (Otherwise ask on the user mailinglist for help.) If Windows can not execute the program add the directory of the program to the PATH (set PATH=%PATH%;dirOfProgram) or specify the absolute path in the executable attribute in your buildfile.

+0

Я забыл прокомментировать, что ваш «не ответ» направил меня на мой ответ. Большое спасибо. – francadaval

Смежные вопросы