我如何告诉eclipse外部工具是否已完成执行?

时间:2014-10-29 14:57:22

标签: eclipse windows powershell batch-file cmd

Eclipse IDE具有可以运行外部工具的功能。我用它来运行批处理脚本。奇怪的是,如果批处理脚本运行powershell命令,那么在我按Enter键之前,powershell命令将永远不会退出。这特别奇怪,因为它在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%的输出,然后它永远挂在进度选项卡中,直到我单击控制台窗口并按回车键。

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

1 个答案:

答案 0 :(得分:0)

找到答案。我需要在我的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

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