escaping special character in groovy

感情迁移 提交于 2020-03-25 13:50:08

问题


I want to run my command in background.And I am trying this in jenkins pipeline This is my command

sh "./node_modules/.bin/selenium-standalone start \&"

But when I run this command & gets single quote because of which the command fails. OUTPUT : ./node_modules/.bin/selenium-standalone start '&'

Can anyone suggest how I should escape the & in groovy so I just get & without single quote.


回答1:


This won't work that easily, first because & is a command for job control in the interactive shell, and also because of how process trees work in Linux.

To make a long story short, if you need to start a command in background, you should use daemonize:

sh label: "starting selenium in the background",
    script: "/usr/local/bin/daemonize ./node_modules/.bin/selenium-standalone start"



回答2:


& is no special character to Groovy. It is for the shell. So if you dont want to start this command in the background but want to pass & as an argument to your script there, you have to use \\& inside "-strings. And if you want to start the script in the background, then just use &.



来源:https://stackoverflow.com/questions/60307097/escaping-special-character-in-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!