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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:15:10+00:00 2026-05-28T16:15:10+00:00

Let’s consider this FOR loop in a Windows batch script: D:\MiLu\Dev\C++\temp :: type string.bat

  • 0

Let’s consider this FOR loop in a Windows batch script:

D:\MiLu\Dev\C++\temp :: type string.bat
@ECHO OFF
FOR %%a IN (%*) DO ECHO %%a

It echoess all the arguments, one by one. Really?

D:\MiLu\Dev\C++\temp :: string.bat foo.obj bar.obj CPPFLAGS=/EHsc
foo.obj
bar.obj
CPPFLAGS
/EHsc

It splits command-line arguments not only on spaces (good), but also on = (not good).
How can I prevent this from happening?

What I want to achieve is simple: A wrapper around NMAKE.exe that specifies /nologo to nmake and also – and this is the problem – to the compiler via the environment variables CFLAGS and CPPFLAGS while at the same time including any settings for CFLAGS and CPPFLAGS supplied on the command line.

In other words, I want to have the script add /nologo to the command line input for CFLAGS and CPPFLAGS even when there is none. Always /nologo! Don’t annoy me with your logo, comrade compiler!

Update

Here’s what I’ve come up with based on Mike’s answer:

@ECHO OFF
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION

FOR %%a IN (%*) DO (
    SET var1=%%a
    ECHO %%a - !var1! - !var1:~0,1!
    IF "!var1:~0,1!" EQU "/" (
        ECHO gefunden: %%a !var1!
    )
)

Going to continue tomorrow …

Update 2

Okay, given that tomorrow is already here I might just as well continue … so here’s a working solution, proudly presented. Feel free to comment on how to improve it.

@ECHO OFF
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION

SET files=
SET   CFLAGS=/nologo %CFLAGS%
SET CPPFLAGS=/nologo %CPPFLAGS%

SET state=normal
FOR %%a IN (%*) DO (
    SET curarg=%%a
    REM ECHO %%a - !curarg! - !curarg:~0,1!
    IF /I "%%a" EQU "CFLAGS" (
        SET state=expecting_cflags
    ) ELSE IF /I "%%a" EQU "CPPFLAGS" (
        SET state=expecting_cppflags
    ) ELSE (
        IF "!curarg:~0,1!" EQU "/" (
            REM ECHO gefunden: %%a !curarg!
            IF "!state!" EQU "expecting_cflags" (
                REM ECHO expecting_cflags
                SET CFLAGS=!CFLAGS! !curarg!
            ) ELSE IF "!state!" EQU "expecting_cppflags" (
                REM ECHO expecting_cppflags
                SET CPPFLAGS=!CPPFLAGS! !curarg!
            ) ELSE (
                ECHO Logikfehler >&2
            )
        ) ELSE (
            SET files=!files! !curarg!
        )
        SET state=normal
    )
)
ECHO Dateien:  !files! >&2
ECHO CFLAGS:   !CFLAGS! >&2
ECHO CPPFLAGS: !CPPFLAGS! >&2
:: ECHO ON
nmake /nologo %files% CFLAGS="%CFLAGS%" CPPFLAGS="%CPPFLAGS%"
ENDLOCAL
  • 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-05-28T16:15:11+00:00Added an answer on May 28, 2026 at 4:15 pm

    One way to work around the problem would be to specify “CPPFLAGS=/EHsc” and then in the loop use %%~a to get rid of the double quotes.

    Another way to work around the problem would be to check the first character of %%a, and if it is a / then prepend a = to it. In order to achieve this you will need to setlocal enabledelayedexpansion, assign %%a to a variable, and then use the %variable:~1,1% notation to extract the first character so you can compare it against /. For more information about this notation, type help set.

    Update (after OP’s update)

    The following fragment appears to work, it is a bit simpler than the corresponding fragment in your solution, and it does not contain any hard-coded names of the arguments, so it is more general-purpose:

    SET allargs=
    FOR %%a IN (%*) DO (
        SET curarg=%%a
        IF "!curarg:~0,1!" EQU "/" (
            SET allargs=!allargs!=!curarg!
        ) ELSE (
            SET allargs=!allargs! !curarg!
        )
    )
    ECHO !allargs!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's suppose I have this piece of code. foreach(string value in myList) { string
Let's say I have this MySQL table: OK.. see the type field? Type 0
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let me preface this question by saying I use TextMate on Mac OSX for
Let's consider the following 3 code lines: struct stat buffer; status = lstat(file.c_str(), &buffer);
Let's say I have this: SolutionSet(const SolutionSet &solutionSet) { this->capacity_ = solutionSet.capacity_; this->solutionsList_ =
Let's say I have saved this kind of data (some text '.date(d).' some text)
Let's say I have this: float i = 1.5 in binary, this float is
Let's create WinForms Application (I have Visual Studio 2008 running on Windows Vista, but
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>

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.