Quotes around comma-separated command-line parameters

Started by john8oy

Quotes around comma-separated command-line parameters   20 October 2014, 21:35

Hi Andrew,

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
SoftPerfect Support forum - Andrew avatar image

Re: Quotes around comma-separated command-line parameters   20 October 2014, 21:44

Hi John,
Could you please post here a specific example (possibly with screen shots) where it breaks the functionality?

Re: Quotes around comma-separated command-line parameters   31 October 2014, 00:48

Hi Andrew.
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

What about?: cmd /c mybatch.bat "user.name1","user.name2"
SoftPerfect Support forum - Andrew avatar image

Re: Quotes around comma-separated command-line parameters   31 October 2014, 09:15

What John says is that in the past versions using the [Logged User] column substitute, passed the following as command line arguments:
user1, user2, user3
While 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

How about: ""user1", "user2", "user3"" or "'user1', 'user2', 'user3'" or '"user1", "user2", "user3"'

Is that the best of both worlds??

Re: Quotes around comma-separated command-line parameters   07 November 2014, 20:54

Maybe a tick box in the Option / Applications tab to turn on or off quotes for parameters. Or do you think there may be a silver bullet approach?

Re: Quotes around comma-separated command-line parameters   04 February 2015, 22:22

Hi Andrew. I still have issues with the Automatic Quotes, is there any plans to make this optional?
Best
John
SoftPerfect Support forum - Andrew avatar image

Re: Quotes around comma-separated command-line parameters   05 February 2015, 00:42

Hi John!

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 %%a
When called as cmd.exe /k test.bat [logged user] it prints a list of users with one user name per line.
You can easily split quoted string back into separate tokens, assuming there's no extraneous separators.
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

Thanks for your response Andrew. I'll amend my scripts going forward. I did enjoy the simplicity in the way the comma automatically split the arguments, and was easy to manually add a quote if needed, but I guess you can't keep everyone happy. cool

John

Reply to this topic

Sometimes you can find a solution faster if you try the forum search, have a look at the knowledge base, or check the software user manual to see if your question has already been answered.

Our forum rules are simple:

  • Be polite.
  • Do not spam.
  • Write in English. If possible, check your spelling and grammar.

Author:

Email:

Subject

A brief and informative title for your message, approximately 4–8 words:

     

Spam prevention: please enter the following code in the input field below.

 **     **   ******    **     **  ********  ******** 
 **     **  **    **   ***   ***  **        **    ** 
 **     **  **         **** ****  **            **   
 *********  **   ****  ** *** **  ******       **    
 **     **  **    **   **     **  **          **     
 **     **  **    **   **     **  **          **     
 **     **   ******    **     **  **          **     

Message: