2

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
    `Tee` is an alias for `Tee-Object`, which belongs to PowerShell only. Is that part of the code being executed in a PowerShell shell or session or is that in a cmd shell? If this is a direct line of code from a batch file, then that is why it does not work. You can run this snippet from PowerShell if you pass in `%Sqlinstance%` correctly. – AdminOfThings Jun 20 '19 at 11:41

2 Answers2

1

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"
Nirav Mistry
  • 949
  • 5
  • 15
0

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"
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27