Quotes around comma-separated command-line parameters
Started by john8oy
Quotes around comma-separated command-line parameters 20 October 2014, 21:35 |
Registered: 11 years ago Posts: 56 |
A recent build update added automatic quotes around passed command-line parameters from column values. This causes me issues with some of the scripts I use. Where a column may have two values comma-separated, these were passed as two parameters to my applications. Now with quotes, my applications see it as one parameter. Is there a way of turning off the quotes in this instance?
Many thanks
John
Re: Quotes around comma-separated command-line parameters 20 October 2014, 21:44 |
Admin Registered: 18 years ago Posts: 3 519 |
Re: Quotes around comma-separated command-line parameters 31 October 2014, 00:48 |
Registered: 11 years ago Posts: 56 |
The best way I can illustrate is this.
The Logged user column's can carry multiple values, Esp Terminal servers. So Passing the command line value [Logged User] could have two scenarios:
Scenario 1
cmd /c mybatch.bat user.name1,user.name2
The above command will pass %1 and %2 as separate parameters.
Scenario 2
cmd /c mybatch.bat "user.name1,user.name2"
This above command will pass %1 as "user.name1,user.name2" there will be no second parameter
As you can see, I would not want Scenario 2, as my batch file will want to process each user individually.
Hope this explains it.
Regards
John
Re: Quotes around comma-separated command-line parameters 31 October 2014, 04:44 |
Registered: 13 years ago Posts: 154 |
Re: Quotes around comma-separated command-line parameters 31 October 2014, 09:15 |
Admin Registered: 18 years ago Posts: 3 519 |
user1, user2, user3While in the latest version it became
"user1, user2, user3"So the batch file no longer recognises these tokens as separate arguments.
This can be desirable in some cases and undesirable in others. I am not yet sure how to make it possible to use both.
Re: Quotes around comma-separated command-line parameters 31 October 2014, 10:07 |
Registered: 13 years ago Posts: 154 |
Re: Quotes around comma-separated command-line parameters 07 November 2014, 20:54 |
Registered: 11 years ago Posts: 56 |
Re: Quotes around comma-separated command-line parameters 04 February 2015, 22:22 |
Registered: 11 years ago Posts: 56 |
Re: Quotes around comma-separated command-line parameters 05 February 2015, 00:42 |
Admin Registered: 18 years ago Posts: 3 519 |
Well, adding a tick box or a special character to avoid quoting doesn't seem to be a good solution.
I'd suggest to de-quote the string and split it in your batch file like this:
@set users=%1 @set users=%users:"=% @for %%a in (%users%) do @echo %%aWhen called as cmd.exe /k test.bat [logged user] it prints a list of users with one user name per line.
Andrey
Re: Quotes around comma-separated command-line parameters 06 February 2015, 15:01 |
This script will demonstrate the technique:
@ECHO OFF ECHO Test 1 CALL :TEST x1,y2,z3 ECHO Test 2 CALL :TEST "x1,y2,z3" ECHO Test 3 CALL :TEST "x=1,y=2,z=3" GOTO :EOF :TEST CALL :SPLIT %1 ECHO Splitting... CALL :SPLIT %~1 GOTO :EOF :SPLIT ECHO 1:%~1 GOTO :EOF(Yes, CMD is THAT bogus.)
Re: Quotes around comma-separated command-line parameters 12 February 2015, 20:29 |
Registered: 11 years ago Posts: 56 |