【问题标题】:In eclipse executing Sass with ANT task. Why have I to set 'executable' to 'sass.bat' instead of 'sass'?在 Eclipse 中使用 ANT 任务执行 Sass。为什么我必须将 'executable' 设置为 'sass.bat' 而不是 'sass'?
【发布时间】:2013-12-13 04:51:15
【问题描述】:

我有这个 ANT 任务在 Eclipse 项目中执行 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 和 sass.bat 都可以从命令行调用,因此 Ruby/bin 文件夹位于系统 PATH 变量中。

我不想为不同的操作系统维护这个文件的两个版本。

我该如何解决这个问题?

【问题讨论】:

    标签: ruby eclipse batch-file ant sass


    【解决方案1】:

    [不是一个答案-但太大而无法评论]

    Windows shell 了解如何扩展 pathext。 Ant 不解释 - 它只尝试 .exe,而不是其他的。

    See comments for Windows Users

    任务委托给 Runtime.exec 显然反过来 调用 ::CreateProcess。是后者定义了 Win32 函数 调用的确切语义。特别是,如果你不放 可执行文件的文件扩展名,仅查找“.EXE”文件, 不是“.COM”、“.CMD”或环境中列出的其他文件类型 变量 PATHEXT。那只被shell使用。

    请注意,.bat 文件通常不能直接执行。一 通常需要执行命令 shell 可执行 cmd 使用 /c 开关。

    一个常见的问题是 PATH 上没有可执行文件。如果您收到错误消息 无法运行程序“...”:CreateProcess 错误=2。系统找不到 指定的路径。看看你的 PATH 变量。只需键入 命令直接在命令行上,如果 Windows 找到它,Ant 也应该这样做。 (否则请在用户邮件列表上寻求帮助。)如果 windows无法执行程序添加程序目录 到 PATH(设置 PATH=%PATH%;dirOfProgram)或指定绝对 构建文件中可执行属性中的路径。

    【讨论】:

    • 我忘了评论您的“不是答案”引导我找到答案。非常感谢。
    【解决方案2】:

    我已经通过添加条件变量 exec_file 来解决这个问题,对于 Windows 系列操作系统,其值为 sass.bat,对于其他操作系统,我添加 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>
    

    【讨论】:

    • 虽然这可以解决您的问题,但它不能回答您的问题。
    猜你喜欢
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多