Hiding output of command in batch file script: Solved!


I was writing a script for automation to deploy web part in share point. So first step was to retract the solution if exists in solution strore of sharepoint. But in case if there is no solution like that in solution store stsadm simply throw an error message “”xxxxxxx.wsp” does not exist in the solution store.”. I simply wanted to show a custom message in place of this error message.
After struggling a hour i could find the solution for this. Below is the sample script for that..

@echo off
SET STSADM=”%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\bin\STSADM.EXE”

SET SolutionWSP=xxxxx.wsp

SET URL=”http://localhost”

echo – Retract the solution if exists
%STSADM% -o retractsolution -name %SolutionWSP% -local -url %URL% 2>NUL
if errorlevel == 0 goto :Flag1
echo ### No solution found like %SolutionWSP% in store
echo.
goto endOfScript

:Flag1
…………………
…………………
Custom script
…………………
…………………
…………………
…………………

:endOfScript

echo.

pause
Actually tweak was of NUL keyword in script.

Write Your Command Here >NUL
:: Above >NUL statement will hide output of if command executes successfully.

Write Your Command Here 2>NUL
:: Above 2>NUL statement will hide error message of if command fails

Write Your Command Here 2>NUL >NUL
:: Above 2>NUL >NUL statement will hides both successful or error message.

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s