I have a .cmd file with this content:
"curl.exe" -H "Content-Type: application/xml" -X POST --data @"post_content.tmp" -w "%{http_code}\n" -o "response_content.tmp" > "http_code.tmp"
I want to get the content of the response into a file and the http_code into another one.
When I run the .cmd I see this:
"curl.exe" -H "Content-Type: application/xml" -X POST --data @"post_content.tmp" -w "%{http_code}\n" -o "response_content.tmp" **1**> "http_code.tmp"
The 1 digit is added before the superior sign. And I have not the expected results.
But if I copy/paste the entire command line directly in the command window, it works.
How can I change my .cmd file ?
I have a .cmd file with this content:
"curl.exe" -H "Content-Type: application/xml" -X POST --data @"post_content.tmp" -w "%{http_code}\n" -o "response_content.tmp" https://myurl > "http_code.tmp"
I want to get the content of the response into a file and the http_code into another one.
When I run the .cmd I see this:
"curl.exe" -H "Content-Type: application/xml" -X POST --data @"post_content.tmp" -w "%{http_code}\n" -o "response_content.tmp" https://myurl **1**> "http_code.tmp"
The 1 digit is added before the superior sign. And I have not the expected results.
But if I copy/paste the entire command line directly in the command window, it works.
How can I change my .cmd file ?
Share Improve this question edited Mar 20 at 22:21 Robert 42.9k18 gold badges109 silver badges172 bronze badges asked Mar 20 at 16:02 coutier ericcoutier eric 1,0219 silver badges20 bronze badges 1 |1 Answer
Reset to default 1Commands entered directly on the Command Prompt CLI and commands in a .cmd script are processed differently.
On the CLI, %
is treated as a literal, unless it is part of an environment variable like %path%
. In a .cmd it is used to escape things like parameters %1
and control variables in loops %%i
, so to use a literal %
, you have to escape it by doubling up to %%
.
If you don't want the command to print before executing, you can also add a @
to the start.
So this content for your .cmd would achieve the same:
@"curl.exe" -H "Content-Type: application/xml" -X POST --data @"post_content.tmp" -w "%%{http_code}\n" -o "response_content.tmp" https://myurl > "http_code.tmp"
%
->%%
. – Andry Commented Mar 20 at 19:23