# Ruby filter: escaping single quote inside the back quote expression

**URL:** <https://discuss.elastic.co/t/ruby-filter-escaping-single-quote-inside-the-back-quote-expression/225615>\
**Category:** Logstash\
**Created:** [March 30, 2020, 5:52am UTC](https://discuss.elastic.co/t/ruby-filter-escaping-single-quote-inside-the-back-quote-expression/225615 "2020-03-30T05:52:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deostroll](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deostroll/32/49539_2.png) [@deostroll](https://discuss.elastic.co/u/deostroll)\
**Post date:** [March 30, 2020, 5:52am UTC](https://discuss.elastic.co/t/ruby-filter-escaping-single-quote-inside-the-back-quote-expression/225615/1 "2020-03-30T05:52:59Z")

</div>

I am trying to run a powershell command to get the system date. In a windows command line you type this:

```auto
powershell -command (date).ToString('yyyyMMddhhmmss')

```

It outputs the current time in the required format. However stashing this into ruby code filter after escaping the single-quote causes error.

```auto
ruby {
		code => 'event.set("ctime", `powershell -command (date).ToString(\'yyyyMMddhhss\')`)'
	}

```

I get the following error:

 ![logstash](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4a03fa23fe03d2964b799b0b0ae3156ffd5c1b11.png)

---

<div class="post-metadata">

**Author:** ![deostroll](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deostroll/32/49539_2.png) [@deostroll](https://discuss.elastic.co/u/deostroll)\
**Post date:** [March 31, 2020, 6:24am UTC](https://discuss.elastic.co/t/ruby-filter-escaping-single-quote-inside-the-back-quote-expression/225615/2 "2020-03-31T06:24:30Z")

</div>

I guess this is a problem with ruby version used by jruby (as of v7.6.1)

However, the following workaround might help:

- Make a script (powershell as in this case) to output the system time in the required format
- Utilize script from within the ruby filter

```auto
ruby {
		code => 'event.set("ctime", `powershell d:/code/ps1/misc/time.ps1`)'
	}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 28, 2020, 6:24am UTC](https://discuss.elastic.co/t/ruby-filter-escaping-single-quote-inside-the-back-quote-expression/225615/3 "2020-04-28T06:24:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
