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

The Archive Base Latest Questions

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

as discussed in an other thread How to avoid cmd.exe interpreting shell special characters

  • 0

as discussed in an other thread How to avoid cmd.exe interpreting shell special characters like < > ^
it is not easy to get all parameters from the command line.

A simple

set var=%1
set "var=%~1"

are not enough, if you have a request like

myBatch.bat abc"&"^&def

I have one solution, but it needs a temporary file, and it is also not bullet proof.

@echo off
setlocal DisableDelayedExpansion
set "prompt=X"
(
    @echo on
    for %%a in (4) do (
        rem #%1#
    ) 
) > XY.txt
@echo off
for /F "delims=" %%a in (xy.txt) DO (
  set "param=%%a"
)
setlocal EnableDelayedExpansion
set param=!param:~7,-4!
echo param='!param!'

It fails with something like myBatch.bat %a, it display 4 not the %a

in this situation a simple echo %1 would work.
It’s obviously the for-loop but I don’t know how to change this.
Perhaps there exists another simple solution.

I don’t need this to solve an actual problem, but I like solutions that are bullet proof in each situation, not only in the most cases.

  • 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:57:08+00:00Added an answer on June 1, 2026 at 3:57 am

    I don’t think anyone found any holes in this, except for the inability to read newlines in the parameters:

    @echo off
    setlocal enableDelayedExpansion
    set argCnt=1
    :getArgs
    >"%temp%\getArg.txt" <"%temp%\getArg.txt" (
      setlocal disableExtensions
      set prompt=#
      echo on
      for %%a in (%%a) do rem . %1.
      echo off
      endlocal
      set /p "arg%argCnt%="
      set /p "arg%argCnt%="
      set "arg%argCnt%=!arg%argCnt%:~7,-2!"
      if defined arg%argCnt% (
        set /a argCnt+=1
        shift /1
        goto :getArgs
      ) else set /a argCnt-=1
    )
    del "%temp%\getArg.txt"
    set arg
    

    The above comes from a lively DosTips discussion – http://www.dostips.com/forum/viewtopic.php?p=13002#p13002. DosTips user Liviu came up with the critical SETLOCAL DisableExtensions piece.

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

Sidebar

Related Questions

As discussed in another question , it's possible to patch cmd.exe to suppress the
As discussed here , C# doesn't support generic attribute declaration. So, I'm not allowed
This is a problem we've seen discussed in other places, with a couple of
I know this has been discussed ad-nauseum but I just don't get some of
I realize that this question is pretty well discussed, however I would like to
I know this topic has been discussed, but not by me yet. As I
CAAnimation does not provide a mechanism for assigning callback functions other than the standard
I know this was discussed on other topics also, what I'm asking is exactly
A question I haven't seen answered that I'm finding very interesting. All the other
As discussed throughout the various MVC questions and blogposts , we know that the

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.