membersound
membersound

Reputation: 86925

How to hand a string with spaces as single parameter?

How can I hand a string that contains whitespaces as single paramter?

SET STRING=this is my teststring
call .\newFile.cmd %STRING%

newFile.cmd:
ECHO %1% //gives: "this"

Upvotes: 1

Views: 59

Answers (2)

jeb
jeb

Reputation: 82418

Try it with

SET STRING=this is my teststring
call .\newFile.cmd "%STRING%"

newFile.cmd:
ECHO %~1

The %~1 removes surrounding quotes.

Upvotes: 2

Space
Space

Reputation: 2042

There are two ways:

1 - Use quotes around the string

SET STRING="this is my teststring"

2 - Escape the spaces

SET STRING=this\ is\ my\ teststring

Upvotes: 1

Related Questions