Hi,
It's hard to explain my problem so I'll just show it to you:
I want to run the following command: run.bat "1 \"3 2\"" and get the following output:
param1: 1 param2: 3 2
Instead, I get nothing.
Here is my script:
@echo off
set arg=%~1
FOR /F "tokens=1*" %%I in ("%arg%") do @echo param1: %%I param2: %%~J
I dont want to use small ticks:
run.bat "1 '3 2'"
It's important for me to use \" because I need to have the possibility of running the following command: run.bat "1 \"2 '3 4'\"" and get the output:
param1: 1 param2: 2 '3 4'
Thanks for the help.
Passing parameters through CMD in batch files
Moderator: DosItHelp
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Passing parameters through CMD in batch files
Any particular reason you have to have all the parameters passed in as one giant parameter?
Re: Passing parameters through CMD in batch files
Hi,
Yes, because this is how my system works.
Thanks.
Yes, because this is how my system works.
Thanks.
Re: Passing parameters through CMD in batch files
Double quotes are special characters. It also looks like you are escaping something with slashes.
If you want an answer that works in your situation then think about showing us exactly what you are doing, rather than contrived examples that don't explain the task.
If you want an answer that works in your situation then think about showing us exactly what you are doing, rather than contrived examples that don't explain the task.
Re: Passing parameters through CMD in batch files
OK then, My goal is as the following, I need to have a batch script that executes a perl script while this perl script might need to get parameters and those parameters can be complicated like:
tasklist | find /i "some process"
and so on.
Why do I must use the batch script? because my system has to execute it using C:\path\to\perl.exe script.pl "arg1" "arg 2"
At the end, the batch call should look like:
run.bat "script.pl \"arg1\" \"arg 2\""
Hope it helps you.
Thanks.
tasklist | find /i "some process"
and so on.
Why do I must use the batch script? because my system has to execute it using C:\path\to\perl.exe script.pl "arg1" "arg 2"
At the end, the batch call should look like:
run.bat "script.pl \"arg1\" \"arg 2\""
Hope it helps you.
Thanks.
Re: Passing parameters through CMD in batch files
Many scripting languages can use a hex or ascii number representation of double quotes. \x22 for example.
Without knowing the exact task and parameters it's hard to suggest anything, that isn't going to break in some way or fashion.
Without knowing the exact task and parameters it's hard to suggest anything, that isn't going to break in some way or fashion.
Re: Passing parameters through CMD in batch files
Hi,
I understand.
Thanks of the help.
I understand.
Thanks of the help.
Re: Passing parameters through CMD in batch files
If the multiple encapsulated parameters (in one parameter) don't contain any further doublequotes, then you may do this to extract it:
penpen
Code: Select all
@echo off
setlocal enableDelayedExpansion
set params=%*
if """" == "%params:~0,1%%params:~-1%" set "params=%params:~1,-1%"
set "N=0"
for %%a in (%params%) do (
set /A "N+=1"
set "param[!N!]=%%a"
)
for /L %%n in (1,1,!N!) do echo param[%%n]=!param[%%n]!
endlocal
goto :eof
penpen