• DOH!

    I meant to remove the -o when I copied and pasted the command.

    If the file is desired/required then run a second command to type out the file.

    @cmd varchar(1000),

    @FileNameOut varchar(200),

    @user varchar(30),

    @pass varchar(30) ,

    @db varchar(30)

    SET @user='sa'

    SET @pass='NotARealPassword'

    SET @db ='SandBox'

    set @FileNameOut ='OutputConsistencia_'+ @db

    select @cmd = 'osql -U' + @user + ' -P' + @pass + ' -S -Q"dbcc checkdb (''' + @db + ''') with no_infomsgs" -o"c:\' + @FileNameOut + '.txt" -w500'

    Exec master..xp_cmdshell @cmd

    create table #t (cmdout nvarchar(255), id int identity)

    set @cmd = 'type "c:\' + @FileNameOut + '.txt"

    Insert #t Exec master..xp_cmdshell @cmd

    Select * from #t