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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:55:44+00:00 2026-06-14T15:55:44+00:00

I am trying to call a command from a batch file which is reading

  • 0

I am trying to call a command from a batch file which is reading in lines from a file.
This is working correctly, except for when the line contains the redirection character >.

Is there a way to tell call to escape this character, or to replace it within the content of the for loop?

I’ve looked at setlocal enabledelayedexpansion and (when the call is updated to use ! it still doesn’t work).

set /p status=<%tmp_file%

for /f "delims=*" %%a in (%tmp_file%) do (
  echo "%%a"
  call check.bat "%%a"
  echo.

  if not "%errorlevel%" == "0" do exit /b 1
)

This produces the following output (when check.bat echo’s %1)

"a"
"a"

"b -> b"
"b -"

I’ve tried to replace > within %%a but I’m not entirely sure how this can be achieved, each time i try, it yields an empty string, i.e.

set line=%a:^>=¬%

EDIT 1
Some more clarification (it appears to only be the case if %1 is set to a variable, and then that variable is used)?:

check.bat:

 set rawinput=%1
 set input=%~1

 echo %1
 echo "%rawinput%"
 echo "%input%"
 echo.

This yields the following output, although im not quite sure why setting %1 to a variable causes it to mangle the value?

 "a"
 "a"
 ""a""
 "a"

 "b -> b"
 "b -> b"
 "b -"

Interestingly b -> b is only output 2 times, echo "%rawinput%" is not showing at all.
Both echo "%input%" and echo "%rawinput%" are writing to a file named b.

This means that the check.bat for b -> b must be interpreted as:

 echo "b -> b"
 echo ""b -> b""
 echo "b -> b"        REM - this is what 'should' be happening, however does appear to be the case, as it writes '' to a file named b
 echo.

If anyone can shed light on why echo "b -> b" in a batch file does not appear to be behaving it would be greatly appreciated.

  • 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-14T15:55:45+00:00Added an answer on June 14, 2026 at 3:55 pm

    Do not try to use call by value, that’s nearly impossible with batch.
    Simply set a new variable with the value and then use the variable name.

    for /f "delims=" %%a in (%tmp_file%) do (
      set "line=%%a"
      call :check
    )
    exit /b
    
    :check
    setlocal EnableDelayedExpansion
    echo(!line!
    endlocal
    exit /b
    

    Edit: Your problem

    You try to call a function with the content "b -> b" using
    call check.bat "%%a" this will expand to
    call check.bat ""b -> b"" and that’s the problem!
    As the > redirect character is now outside of the quotes, it will redirect the output of check.bat to the file b.
    You can escape a special character (outside of quotes) when using a call, but this is a bit advanced and has many problems.

    So, I would recommend again, not using directly the content in a call.
    You could use a reference, like

    for /f "delims=" %%a in (%tmp_file%) do (
      set "line=%%a"
      call :check line
    )
    

    check.bat

    setlocal EnableDelayedExpansion
    set "var=!%1!"
    echo(!var!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call MSBuild from a command line. Everything was working fine
I have a VBScript file which I am trying to call from a Batch
I'm trying to call a java program from python using command line. The code
I'm trying to call a class (main method) from command line (Windows) with Java.
I am trying to call a batch file from an application, but I want
I'm trying to call 'sed' from Python and having troubles passing the command line
I'm trying to call a command-line application (let's call it SomeTerminalApp ) from Java,
How would one call a shell command from Python which contains a pipe and
I'm trying to call an ImageMagick command from Python 2.7 using subprocess.call. My problem
I'm trying to execute a 3rd party application, called from a .cmd batch file,

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.