0
votes

The Eclipse IDE has a feature where one could run external tools. I use it to run batch scripts. Oddly if a batch script runs a powershell command, the powershell command will never exit until I hit enter. This is especially odd since it exits just fine when running in cmd. How should I correct my script so that it runs as expected via the eclipse external tools?

Current script (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

In cmd, I see "Hello 1", the output of %CMD%, and "Hello 2". In Eclipse, I see "Hello 1", the output of %CMD%, and then it hangs in the progress tab forever until I click the Console window and press the enter key.

I tried passing the -NonInteractive flag to Powershell. I tried having my Powershell script echo a newline at the end. Not sure how to get this to "just work".

1
Try adding an exit to the end of the command?arco444

1 Answers

0
votes

Found the answer. I needed to add a NUL redirect to the end of my Powershell command. So it looks like this:

@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

Note that I also removed the dubugging code from the script found in my question. If you add that code back in, you'll see that it echos everything now.