Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

How do you pass quotes to a command line? #108

bluejay ·
I want to pass a parameter to a bat file via the command line in command builder that is quoted. Is there a way to escape the quotes? I've tried \" but the quote gets striped away. I've also tried double quotes. Any ideas?
robinshen ADMIN ·
Please use the character "`" to quote params containing spaces.

Robin
bluejay ·
It's not a space issue. Your suggestion doesn't work. It needs to be double quotes. I'll clarify.

execute a command line that executes a .bat file with a param that is a parameter for an ant task (e.g. -Dsomeparm=value,value) in order for the ant task to work properly this needs to have quotes. (e.g. -D"someparm=value,value") otherwise it thinks the second value is another target.

Any suggestions?
robinshen ADMIN ·
If you surround any string in the command line with "`", it will be treated as one parameter instead of two even there is a comma in the parameter in your case.

Please give it a try and tell me the result.

Regards.
Robin
drdt ·
Did this end up working? I am having a similar problem, trying to pass the QuickBuild instance URL to my application:

> cmd /c "..\tools\ci\blame_run.pl data ${repository["perforce"].headRevision} ${build.url}"

The ${build.url} value has an ampersand (&) in it, which is interpreted by the command shell (as 'do this also'), and as a result I get an error ('sp' is not recognized as an internal or external command, operable program or batch file.), plus the URL in my output is incomplete.

I got around this problem by passing it as an environment variable:

> BUILD_URL="${build.url}"

BUT, the quotes are stripped off by QuickBuild, which is different behavior from that of the command shell. As a result, my script will either work in QuickBuild or from the command line, depending on how I code it, but not both. I think this is a bug.

(Really, I like your behavior better than Windows', but I can't imagine Microsoft is going to change it on their end.)
robinshen ADMIN ·
If you would like to pass the url as one of the argument, you can do the following:

cmd /c ..\tools\ci\blame_run.pl data ${repository["perforce"].headRevision} `${build.url}` 


Also it is not a necessary that the url being quoted when passed as environment variable, so you can define it as:
BUILD_URL=${build.url}


In this way, I think your script will be able to work both in QuickBuild and command line.

Regards
Robin
drdt ·
If under CMD I do
> set BUILD_URL=http://mysystem:8080:app.do&sp=5
Windows will give an error ('sp is not a valid command').

If under CMD I do
> set BUILD_URL="http://mysystem:8080:app.do&sp=5"
then BUILD_URL is set to:
"http://mysystem:8080:app.do&sp=5"
(quotes included), and my script has to trim off the quotes to interpret the value.

If from QuickBuild, I set either:
BUILD_URL="http://mysystem:8080:app.do&sp=5"
BUILD_URL=http://mysystem:8080:app.do&sp=5
then BUILD_URL is set to
http://mysystem:8080:app.do&sp=5
(no quotes), and my script fails because there are no quotes.

If I adjust my script to *not* expect quotes, then it works from QuickBuild but fails under the command line.

However, I will try the backticks and see what happens.
robinshen ADMIN ·
I see. how about setting the environment as:
BUILD_URL=`${build.url}`

The character ` will be replaced by quote, which will have the same effect as define
set BUILD_URL="http://mysystem:8080:app.do&sp=5" in command line.
drdt ·
> The character ` will be replaced by quote

This did not happen on my system. I am running Windows Server 2003 (in case that matters), and the backtick was not passed through or replaced.

I finally worked around the problem by having my script search for and trim the quotes if it finds them.
southe ·
I'm also running into a problem with this. If i encapsulate my string with the "`" character, QuickBuild is actually trying to process the "`" character as part of the string.

DEBUG - Executing command: cmd /c `c:\program files\beyond compare 2\bc2.exe`

QuickBuild, 2.1.12
Windows 2003 Server x64
robinshen ADMIN ·
This problem is solved in QB 2.x. Just write your command as:
cmd /c "C:\program files\beyond compare 2\bc2.exe"
However back slashes quoted need to be escaped just as a Java string.
absalom1 ·
I have similar problem like above.

I want to run a command like below on Shell/Batch command step but I can't.
bash -c "source aaa.sh&&bbb \"ccc:222 ddd:333\""
(bbb is a function name in aaa.sh and required two parameters like above)

Could you help me to send a command like above?
robinshen ADMIN ·
Can you please put this command in a batch file and call that batch file in QB to see if it works?
georg ·
Hello,

I have the similar issue. I have prompt variable and which should be passed as a value to system variable to maven command.
We should have something like mvn plugin -D<variable1>="value1" -D<variable2>="value2". I couldn't specify double quotes although tried all options with ' or ` or \" or "".

It doesn't work. From cmd it doesn't work as well unless you specify values in double quotes.

Do you know is right now is possible to specify double quotes?
robinshen ADMIN ·
Unfortunately double quotes have special meaning in QB command line and can not be used in this way. Right now the only option is to wrap the command in a batch file. Please file a ticket for this at track.pmease.com.
Productivity ·
I kind of have a similar issue with quotes on my side, except for me it is:

1) On a Linux Machine (running Ubuntu);
2) With a single quotation mark (instead of the double quotation mark)

Basically, if I try to run the following command:

/bin/bash -c "echo Hello World"


It works fine within a "Shell/Batch Command" build step in QuickBuild but if I run the following command:

/bin/bash -c 'echo Hello World'


The build step fails instead with the following error:

13:50:45,352 ERROR - Step 'master>Container>Execute bash command single quotation mark' is failed: Failed to run command: /bin/bash -c 'echo Hello World'
Command return code: 1
Command error output: Hello: -c: line 0: unexpected EOF while looking for matching `''
Hello: -c: line 1: syntax error: unexpected end of file


The exact same command does not fail if I execute directly it in a terminal in the same Linux build node. Any idea why?
robinshen ADMIN ·
I guess here single quote is interpretated by shell to quote parameters as a whole, however if passed to a ProcessBuilder in JVM it is interpretated literally so JVM thinks bash is being called with four separate parameters respectively:
-c
'echo
Hello
World"


So in this case, please use double quotes to quote single parameter containing spaces as QB itself parses double quotes and then group parameters inside them as pass them a single param.