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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:04:59+00:00 2026-05-31T08:04:59+00:00

I am running input arguments as a command in my dos batch file as

  • 0

I am running input arguments as a command in my dos batch file as I asked in:
Run an input parameter as command in dos batch script.
That works, however the problem I am having: checking if the input command if it’s empty.
What I do:

SETLOCAL
set CMD=%*
echo Running command [%CMD%]
IF "%CMD%"=="" (
 echo "Input argument missing: command"
 GOTO :end
)
echo "XXX %CMD%"

And running:

script.bat echo "a b c"

Will output:

Running command [echo "a b c"]
b was unexpected at this time.

This occurs in the IF condition, but why?

How can I check if my input is empty. I know how to check if a string is empty in dos, but for some reason it doesn’t work in this combination 🙁
BTW: If I remove the IF condition it works well, that is: the command is executed correctly.

  • Ed
  • 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-31T08:05:01+00:00Added an answer on May 31, 2026 at 8:05 am

    Test for the absence of parameters first, then assign and process the command:

    IF .%1 == . (
     echo "Input argument missing: command"
     GOTO :eof
    )
    
    SETLOCAL    
    set CMD=%*
    echo Running command [%CMD%]
    echo "XXX %CMD%"
    

    As to the “Why?”, it’s because the quotation mark in the value of CMD (the one before a) closes the quotation mark before %CMD%, and so the string appears as "echo "a b c"", and thus b becomes separated from the string, which causes the command processor to fail. (It expects a comparison token, like == or EQU, but not some strange b).

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

Sidebar

Related Questions

I wrote a script to run a command-line program with different input arguments and
This is my (windows) command line argument for running my script. C:\PathToR\Rscript.exe Rfile.r input
i'm trying to send fake keyboard input to an application that's running in a
Running into a problem where on certain servers we get an error that the
I wanted to run a .cmd file from Java. I have something which works
I have a Python application (command line tool running on a machine M1) that
My ruby script gets certain inputs from command line arguments. It check if any
I have some long running scripts with breaks requiring input/interaction to continue but when
running git instaweb in my repository opens a page that says 403 Forbidden -
Running OS X Leopard an MacBook Pro from Jan. 2008. I used to run

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.