逃避groovy中的特殊字符 [英] escaping special character in groovy

查看:386
本文介绍了逃避groovy中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后台运行我的命令,我正在詹金斯管道中尝试这个 这是我的命令

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 \&"

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

但是当我运行此命令时&由于命令失败而得到单引号. 输出:./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.

推荐答案

这并不容易,首先是因为&是交互式外壳程序中用于作业控制的命令,也是因为进程树在其中的工作方式Linux.

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.

长话短说,如果需要在后台启动命令,则应使用 daemonize :

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"

这篇关于逃避groovy中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆