How do I tell eclipse that an external tool is done executing? - eclipse

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".

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.

Related

launch cmd run command isn't working

I am working on a script or batch file (or combo of the two) which imports an outlook prf file, then launches a new cmd.exe window runs a application specific program which when passed a server cluster name pulls in an outlook data file in the previously created outlook profile. So i have the vbs script that checks for the outlook profile if it doesn't exist it imports the prf. That's working fine, now the program i need to is called addiman.exe the server cluster name is gsiapp...the manual method is i launch a cmd windows and type "addiman gsiapp" i wish to automates this by calling it in a routine called :Filesite the below command has been unsuccessful, it launches a new cmd.exe window but doesn't run the command.
:ImportPRf
call cscript \\gsf1\Apps\Scripts\public\deployprf.vbs
GOTO :FileSite
:FileSite
start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe" GSIAPP
GOTO :EXIT
:Exit
Exit
start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe GSIAPP"
try this, because cmd.exe interprets the part between "" as comand and ignores the GSIAPP statement
wild guess. Try adding another call before the "start" - like this
:FileSite
call start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe" GSIAPP
problem solved, the full path isn't needed. just had to putt "addiman GSIAPP". Thanks everyone who provided suggestions.

How to execute cscript using windows task scheduler?

The problem: When I double click the .bat file it executes as expected. When I schedule it in Windows Task Scheduler it executes except the line that has cscript.
Content of .bat file:
#echo off
cls
cscript CSV_To_Excel.vbs c:\tableaudata\test.csv c:\tableaudata\test.xlsx
echo.file converted >>log.txt
What is throwing me off is the fact that log.txt gets created indicating that the .bat file is being executed. But .xlsx is not created. However, on manually double clicking .bat both log.txt and test.xlsx is created.
What could be the problem?
Resolved!! In the windows task scheduler I had to click "change user or group" button and add "Administrators" group.
To help debug the situation, add the following to the end of your cscript command line:
>>c:\MyCScriptOutput.txt 2>&1
Then, check to see if the c:\MyCScriptOutput.txt file has any error message(s) in it. If it does, please add this information (both the command line and the output) to your question.
I'm speculating, but the problem might be that cscript is trying and failing to run interactively, so you could try replacing "cscript" in your command line with "cscript //Nologo //B", to see if that fixes it.
The main problem is you don't specify full path to your CSV_To_Excel.vbs
Scheduler execute script from c:\windows\system32 (where schtasks.exe located)
So, your batch call to cscript should be
cscript %~dp0\CSV_To_Excel.vbs c:\tableaudata\test.csv c:\tableaudata\test.xlsx
echo.file converted >> %~dp0\log.txt

How to force invoked command's STDOUT into invoking cmd.exe's STDOUT?

Context: Oracle Enterprise Manager has a feature to "execute host command." If into that feature I enter "dir c:\temp" then the output window echos the command and then shows a directory listing. If into that feature I enter "powershell dir c:\temp" the output window shows only the echo'd command. No directory listing. If on the target machine I enter those two commands in both cases I get the echo'd command followed by a directory listing.
I hypothesize that what I see in the cmd.exe window on the client blends two stdout streams: one from the cmd.exe itself and one from the invoked process (powershell dir c:\temp). The Oracle thing seems to recognize only the cmd.exe's stdout.
Is there some way I can force the stdout from the invoked process to be in the cmd.exe's stdout stream so that Oracle will recognize it and the thing I am trying to build will work?
I don't think you can directly pipe the output from one program back into STDOUT of a parent cmd.exe - assuming that is what Oracle is doing at some level.
That being said, you could try something clever like the following:
cmd /c "powershell -Command ""& echo Hello" > %TEMP%\a.txt & TYPE %TEMP\a.txt
Basically this is capturing the output from PowerShell, placing it in a temporary file, then dumping that file back onto STDOUT in cmd.exe. A nice touch would be cleaning up the temp file with a & DEL %TEMP%\a.txt on the end of the command.
You will probably need to toy around with the command line to account for any quirks in how Oracle is passing things along - my guess is that it is invoking cmd.exe /c directly so you can probably leave that part off.

How to start powershell with a window title?

I have a batch file that allows me to go to particular folder based on my input.
d:
cd d:\test\bits
#ECHO off
cls
:start
ECHO.
ECHO 1. Perl
ECHO 2. Python
set choice=
set /p choice=type in number to go to appropriate code folder:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto pl
if '%choice%'=='2' goto py
ECHO "%choice%" is not valid, try again
ECHO.
goto start
:pl
cd code\pl
goto end
:py
cd code\py
goto end
:end
start "bits"
At the end of execution, a command prompt window with the title "bits" opens up and is in the specified directory corresponding to the input choice. This is all good. But I want to have the same thing done with Powershell.
If, instead of start "bits", I put, start powershell, in the last line, I can get Powershell console to open. By doing this, I have two issues.
Powershell console is still in d:\test\bits folder and not in the one I intended it to go.
I cannot get the title to be bits
How do I get the functionality I want with Powershell?
From what I expected and what I was able to reproduce with your script, the current directory is set to the intended one (d:\test\bits\code\pl if I enter 1)
For the title part, you can do the following:
start powershell -NoExit -command "$Host.UI.RawUI.WindowTitle = 'bits'"
If you add this to your powershell profile.ps1 you can get the window title to show the current running script and if you are just opening a window with no script then 'pwsh' will be displayed.
Will be systematic with no need to add a line on top of each script. The other answers
combined with $MyInvocation.MyCommand seem to give the name of the profile.ps1 instead when running a script from the context menu.
This can also be tweaked to change the result.
[console]::title = Split-Path -Leaf ([Environment]::GetCommandLineArgs()[-1]).Replace('pwsh.dll','pwsh')
Works on both PS 5 and 7 . For ver. 5 replace pwsh.dll by powershell.exe

How to create a file without a Command Prompt window

I'm using WinRAR SFX module to create an installation, and use its presetup option to run some preliminary tests.
Since wscript can only accept vbs file, and not the script itself, I first run "cmd /c echo {...script code...} > setup.vbs", and then I run "wscript setup.vbs". The run of the first cmd command opens a brief command window, and I would really like to avoid this. I thought of using RunDll32 to write this data, but couldn't find any suitable API to use.
Can anyone think of a way to bypass it and create a small file with a small VBScript text without opening a Command Prompt window?
Thanks a lot,
splintor
Is the script code already in a file? If so,
You can use the TYPE command to send the script to a file:
TYPE [script_file] > setup.vbs
or COPY the script file:
COPY [script_file] setup.vbs
If the script code is in the body of your cmd, you can use the START command to run the cmd without a window (/b flag):
START /B cmd /c echo {...script code...} > setup.vbs
Rather than use cmd /c echo {...script code...} > setup.vbs as a presetup step, perhaps you could package a VBscript with your install that does your preliminary tests and creates setup.vbs, and then calls setup.vbs for you. You'd have to put this in the setup portion of the WinRAR script.
You can call another VBScript from VBScript like this:
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "wscript d:\setup.vbs, ,True
See this MSDN link for the syntax of the Run command.