开发者

How to write a CVS wrapper script

I'd like to write a CVS wrapper script that executes the command on another machine using RSH but am having trouble with quotes.

#!/bin/csh -f
rsh <machine> cvs $*:q

The problem is that even though the arguments are passed with quotes RSH seems to drop them when the command is executed. The following command should appear as 3 arguments at the destination but has 4 instead.

cvsWrap diff -D "2011-05-01 00:00:00"

I'm not looking for advice on how not to use rsh since I'm really using qrsh, an rsh-compatible version for SGE. I considered using an interpreter but I don't know how to escape the quotes within strings:

rsh <machine> /bin/csh -c "cvs $*:q"

I'm most familiar with c-shell but would be willing to consider开发者_如何学JAVA a bash script if someone were to write it. How can I write this CVS script?


Invoking:

cvsWrap diff -D \"2011-05-01 00:00:00\"

will probably help but isn't ideal.

The underlying issue is that csh will throw away your quotes as an opening gambit as it groups things up to put them in argv, so your quotes never really make it into cvsWrap. Instead you have

argv[1] == diff
argv[2] == -D
argv[3] == 2011-05-01 00:00:00

all they do is get the string with a space in it into the same argument.


I declared defeat and just wrote the script in Groovy.

#!/usr/bin/env groovy
def rshCmd = "qrsh -cwd -now n -b y".split().toList()
def cvsCmd = ["cvs"] + args.collect { '"' + it + '"' }
def process = (qrshCmd + cvsCmd).execute()

def outTh = Thread.start {
  try {
    process.in.eachLine {
      System.out.println it
    }
  } catch(e) {}
}

def errTh = Thread.start {
  try {
    process.err.eachLine {
      System.err.println it
    }
  } catch(e) {}
}

outTh.join()
errTh.join()
process.waitFor()
System.exit(process.exitValue())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜