I'm trying to get the last return code from an SSH shell in linux.
I'm using the command:echo &? to get it.
I've written following code but it's not working:
int last_len = 0;
Pattern p = Pattern.compile("echo $?\r\n[0-9]");
while(in.available() > 0 ) {
last_len = in.read(buffer);
String str = new String(buffer, 0, last_len);
Matcher m = p.matcher(str);
if(m.find()) {
return Integer.parseInt(m.group().substring(9));
}
}
What am I doing wrong?