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

  • SEARCH
  • Home
  • 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 7719817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:30:38+00:00 2026-06-01T03:30:38+00:00

i am working on a batch script. i want to store the count of

  • 0

i am working on a batch script.

i want to store the count of row’s in variable.

like

set var = mysql -uroot -proot -e”select count(*) from table”;

i also tried to do it other way like

 set var= mysql -uroot -proot -e "select count(*) from table into outfile 'F:\count.txt'";

 for /f %%a in ("F:\count.txt") do ( 
set output = %%a
echo %output% 

pause 

)

In above code the variable “output” shows nothing(empty).

please help me out.

  • 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-01T03:30:39+00:00Added an answer on June 1, 2026 at 3:30 am

    I can see at least two issues in your script:

    1. A string in double quotes inside IN( ) is treated as a literal, not as a file path/name, unless you specify the usebackq option, which enforces different semantics, whereby either double-quoted string or non-quoted one is treated as a file name.

    2. You are storing <space>%%a into the output<space> variable, not %%a into output.

    After you’ve fixed those two, there will remain one (probably, just one) more issue. You are assigning a value to a variable and then evaluating the variable in the same bracketed block (which is your loop body) using immediate variable expansion (%var%). This cannot work as expected. The thing is, a bracketed block is parsed entirely as a single unit, i.e. all its commands are parsed before the first one executes. As you can guess, your %output% expression will in this case evaluate to nothing, because output is not yet assigned a value at the time of parsing. (And when it is assigned a value, it will change nothing, because the previous (empty) value will already have replaced the expression.)

    You can solve this using delayed variable expansion, which, as can be guessed, uses a different timing for evaluation. First, you should enable delayed expansion by issuing the SETLOCAL EnableDelayedExpansion command, then use a slightly different syntax: !var! instead of %var%.

    So, if we address all the issues mentioned above, the loop may look like this:

    …
    SETLOCAL EnableDelayedExpansion
    
    FOR /F "usebackq" IN ("F:\count.txt") DO (
    SET output=%%a
    ECHO !output!
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my classpath to be set via a batch file. I'm working on
I had a problem with set not working in a batch file; it took
Let's say I'm working on a little batch-processing console app in VB.Net. I want
I'm working on a batch script that will let me delete files older then
The following batch script prints out my current working directory. echo %cd% But I
My batch file terminates prematurely after I assign the first environmental variable (script output
Two questions pertaining to a FTP Batch upload script I'm working on. 1) My
I am working on a batch file to gather the mac addresses of two
Let's consider this FOR loop in a Windows batch script: D:\MiLu\Dev\C++\temp :: type string.bat
What I would like I would like to easily run a batch file without

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.