Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

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 scriptRun 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

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

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
Source Link
edbras
  • 4.4k
  • 12
  • 56
  • 81

checking input command in dos batch file?

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