我正在尝试将正则表达式计算为命令的标准输出。即使正则表达式应该匹配它似乎并没有这样做:
> [#] Command "pm2 list"
> [#] stdout
> [#] should match /.*online.*/ (FAILED - 1)
> [#]
> [#] Failures:
> [#]
> [#] 1) Command "pm2 list" stdout should match /.*online.*/
> [#] Failure/Error: its(:stdout) { should match /.*online.*/}
> [#] ArgumentError:
> [#] invalid byte sequence in US-ASCII
> [#] /bin/sh -c pm2\ list
> [#] ┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬─────────────┐
> [#] │ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
> [#] ├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼─────────────┤
> [#] │ app │ 0 │ fork │ 3684 │ online │ 0 │ 5m │ 13.898 MB │ unactivated │
> [#] └──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴─────────────┘
> [#] Use `pm2 desc[ribe] <id>` to get more details
> [#]
> [#] # /tmp/busser/suites/serverspec/localhost/nodejs_spec.rb:10:in `block (2 levels) in <top (required)>'
> [#]
> [#] Finished in 0.77549 seconds (files took 0.19867 seconds to load)
> [#] 3 examples, 1 failure
为什么正则表达式不匹配?
在食谱中运行的类似正则表达式可以正常工作:
...
process_check = Mixlib::ShellOut.new("pm2 list")
process_check.run_command
if process_check.stdout =~ /(stopped|online)/
...