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 9225007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:28:17+00:00 2026-06-18T04:28:17+00:00

Platform Windows XP When writing a command file (.bat) how can i catch the

  • 0

Platform Windows XP

When writing a command file (.bat) how can i “catch” the output from a command into a variable ?

I want to do something like this

SET CR='dir /tw /-c b.bat | findstr /B "[0-9]"'

But this do not work

Regards Stefan

PS
No, I can not dowload grep, cygwin or any other software, it have to be the CMD
DS

  • 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-18T04:28:18+00:00Added an answer on June 18, 2026 at 4:28 am

    You can use FOR /F and go through some loops inside a batch file to capture the output:

    @echo off
    setlocal enabledelayedexpansion
    set var=
    for /f "tokens=* delims=" %%i in ('dir /tw /-c b.bat ^| findstr /B "[0-9]"') do set var=!var!^
    
    %%i
    
    echo %var%
    

    It is especially important that there are two newlines between !var!^ and the %%i below.

    Additionally you need to escape (again using ^) all characters inside the command line for FOR that have special meaning to the shell, such as the pipe in this instance.

    The solution works by iterating over the output of the command and appending each line to the contents of var incrementally. To do that in a somewhat convenient manner the script enables delayed variable expansion (the !var! syntax).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Platform: Windows 7, Windows XP Software: DOS I know about command line length limitation
Utility: NMake Platform : Windows 7 I have the following Makefile FILE = $(shell)
I would like to develop applications for the Windows platform & at the very
Just curious if I'm creating a shared memory array on Windows platform like so:
I'm writing a quick server app for something so don't really want to write
So I am writing a cross-platform (so far plans for Windows and Ubuntu) application
I am writing a cross-platform OpenGL function loading library. On Windows, the compiler (oddly
I am writing an command line application in C and from within the program,
I'm writing a cross-platform code, which should compile at linux, windows, Mac OS. On
I'm writing a cross-platform program in Java and want to stick the configuration files

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.