SQLCMD , 'tee' is not recognized as an internal or external command

Viewed 1996

I've fetchDb.bat file that calls many .sql files to upgrade the database to last version

this is the command used to execute .Sql File content

sqlcmd %Sqlinstance% -d DataBase -i "fileName.sql" | tee "FileNameOutput.txt"

but this message Always appear for me 'tee' is not recognized as an internal or external command , operable program or batch file.

2 Answers

tee ( Tee-Object ) is cmdlet which is supported in powershell. so you have to use powershell for this or you can use below command to save output to file in bat

 COMMAND >> Filename

in your case :

sqlcmd %Sqlinstance% -d DataBase -i "fileName.sql" >> "FileNameOutput.txt"

From a CMD shell, you can do either of the following, but make sure your batch file only echoes what you want to see in your output file. This will allow you to use tee.

Using a batch file:

PowerShell.exe -Command ".\fetchDB.bat | tee 'filenameoutput.txt'"

Using commands that can be passed to PowerShell:

PowerShell.exe -Command "$sqlinstance='servername'; sqlcmd.exe -S $sqlinstance -d Test -i 'fileName.sql' | tee 'filenameoutput.txt'"

# You can use this option if your CMD shell has variable sqlinstance defined
powershell.exe -Command "sqlcmd.exe -S %sqlinstance% -d Test -i 'fileName.sql' | tee 'filenameoutput.txt'"

From a PowerShell console, you can just call the fully qualified batch file and pipe to tee.

.\fetchdb.bat | tee "filenameoutput.txt"
Related