【问题标题】:How do I tell eclipse that an external tool is done executing?我如何告诉 Eclipse 外部工具已完成执行?
【发布时间】:2014-10-29 23:52:36
【问题描述】:

Eclipse IDE 具有一项可以运行外部工具的功能。我用它来运行批处理脚本。奇怪的是,如果批处理脚本运行 powershell 命令,则 powershell 命令将永远不会退出,直到我按 Enter 键。这特别奇怪,因为它在 cmd 中运行时退出就好了。我应该如何更正我的脚本,以便它通过 eclipse 外部工具按预期运行?

当前脚本(foo.bat):

@echo off
echo "Hello 1"
REM Configure this to your installation of maven.
SET "CMD=C:\foo.ps1"

REM Reformat args to be Powershell friendly.
SET "ARGS=%*"
SET "ARGS=%ARGS: =' '%"
PowerShell.Exe -Command "%CMD%" '%ARGS%'
echo "Hello 2"
EXIT /B

在 cmd 中,我看到“Hello 1”、%CMD% 的输出和“Hello 2”。在 Eclipse 中,我看到“Hello 1”,%CMD% 的输出,然后它永远挂在进度选项卡中,直到我单击控制台窗口并按 Enter 键。

我尝试将 -NonInteractive 标志传递给 Powershell。我尝试让我的 Powershell 脚本在最后回显一个换行符。不知道如何让它“正常工作”。

【问题讨论】:

  • 尝试在命令末尾添加exit

标签: eclipse windows powershell batch-file cmd


【解决方案1】:

找到了答案。我需要在我的 Powershell 命令的末尾添加一个 NUL 重定向。所以它看起来像这样:

@echo off
REM Configure this to your installation of maven.
SET "CMD=C:\foo.ps1"

REM Reformat args to be Powershell friendly.
SET "ARGS=%*"
SET "ARGS=%ARGS: =' '%"
PowerShell.Exe -Command "%CMD%" '%ARGS%' < NUL

请注意,我还从问题中找到的脚本中删除了调试代码。如果您重新添加该代码,您会看到它现在回显了所有内容。

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多