Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:22:31+00:00 2026-06-02T19:22:31+00:00

I do some command line batch (.bat) with sqlcmd as this way: sqlcmd -i

  • 0

I do some command line batch (.bat) with sqlcmd as this way:

sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE

and i need an output file (it’s works currently) and also the output trought the screen to do something like:

@echo off
echo The result of the query was:
    sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
pause
CHOICE /C:YN /M "Is the result accord?"
IF ERRORLEVEL 2 GOTO ENDWITHERROR
IF ERRORLEVEL 1 GOTO STEP2

Note:

  • Yes, the script works suscefull, it’s not an issue question.
  • And yes, I’ve a “print “something” on my sql. The log file gets the output.

Thanks a lot!

Similar question without answer:
How to run a sql script file using sqlcmd and output to both shell and file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:22:32+00:00Added an answer on June 2, 2026 at 7:22 pm

    I also couldn’t find a better way then @Sparky proposed. The following code adds his suggestion:

    @echo off
    
    :: this will execute the script into PROCESS.log
    sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
    
    :: this present the contents of PROCESS.log to the screen
    echo The result of the query was:
    type PROCESS.log
    
    pause
    CHOICE /C:YN /M "Is the result accord?"
    IF ERRORLEVEL 2 GOTO ENDWITHERROR
    IF ERRORLEVEL 1 GOTO STEP2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way to log everything that appears on the command line
First some background. I have a batch-type java process run from a DOS batch
We have a few C++ solutions and we run some build scripts using batch
I have a batch script that triggers an exe (c++ code) with command line
I have a command line executable that alters some bits in a file that
Just converting some shell scripts into batch files and there is one thing I
I have built some bundles for my Debug profile from the command line. I
I would like to create some batch scripts to move some files around. But
I'm forced to use DOS to write some batch scripts. How to do arithmetic
I've got a MS DOS command line issue, I'm trying to pass some arguments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.