2014-02-26 49 views
1

我正在用Groovy lang丢掉我的头发,它已经连续4天毁了我,并且它正在计数。groovy,字符串拒绝是一个bigInt,是奇数而不是

我需要做的是执行一个外部进程,读取stdout,获取该值并将其转换为大整数。我有什么

def str ='openssl x509 -in "'+ file + '" -serial -noout'  
def command = "cmd /c " + str; 
def proc = command.execute(); 
proc.waitFor(); 
def response = "${proc.in.text}" 
def result = response.split('=')[1] 
log.info result 
// outputs: 7434F30AEE5F2001530C7F0C4844E9EE 
log.info result.class.name 
// outputs: java.lang.String 

好吧,非常酷,让我们去上:

def big = new BigInteger(result.decodeHex()) 

不 - 不,不能这样做:

java.lang.NumberFormatException:奇数个字符在十六进制字符串

与此同时,在另一个脚本:

def numb = '7434F30AEE5F2001530C7F0C4844E9EE' 
log.info numb.class.name 
// outputs : java.lang.String 
b = new BigInteger(numb.decodeHex()) 
log.info b 
// outputs : 154465376439281796222583609645190146542 

回答

4

你应该修剪result从空格,换行和类似的东西 - 而在此之后,打印出的字符数在这个字符串,如果他们甚至或静止奇。

+0

我很伤心,说明太简单了 –

+2

@Erki如果你在做Smutje建议后仍然有问题,那么可能奇数是1,单字符字符串被自动转换为字符您使用的一种“Groovy默认方法”。你的旅程看起来很像我在4到6年前经历过的,当时我使用了Codehaus Groovy,尽管我的头发可能会减少。 –

+0

是的,事情是,我在SoapUI中开发,并没有太多可用的调试选项。 –

相关问题