Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

parsing the end of lines in std output

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have the following scenario where by I am want to parse the last few lines in a std output and find not the very last occurence of an integer value but the sceond occurence

the stdout has the followng last few lines that i am interested in

The stdout is the console ...

blah blah blah above which also has loads of numeric values ...
C:\HOME........
C:\HOME.....
C:\HOME\abc\Test>0

C:\HOME\abc\Test>Connection closed by foreign host.
1


The code i have to retrieve the value 0 in the third line is

Any ideas why the below is not returning the value 0 ???



int ReturnTheSecondLastThatHasTheEndOfLineInteger(String output) {
String[] words = output.split("[\n]");
for (int i = words.length-3; i-- > 0;) {
try {

Integer num = Integer.parseInt(words[i].trim());
return num;
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic