git - Escaping characters in Ruby Shell -


i have bash command:

git log --numstat --pretty="%h" -1 | awk 'nf==3 {plus+=$1; minus+=$2} end {printf("+%d, -%d\n", plus, minus)}' 

i want assign command string variable , process output using exec(stringname) method.

the string command breaks @ "+%d, -%d\n". there way can escape these special characters?

if need quote has quotes in already, use %q method:

command = %q[git log --numstat --pretty="%h" -1 | awk 'nf==3 {plus+=$1; minus+=$2} end {printf("+%d, -%d\n", plus, minus)}'] 

doing of in ruby gives lot more control:

require 'open3'  open3.popen3('git', 'log', '--numstat', '--pretty="%h"', '-1') |stdin, stdout, stderr, wait_thr|   stdout.each_line |line|     if (line.match(/\a(\d+)\s+(\d+)\s+(.*)/))       puts '+%d, -%d' % [ $1, $2 ]     end   end end 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -