[Solved] Read last line from Process
Posted
#1
(In Topic #394)
Regular

Considering the following concept bash:
Code
command | while read line; do
if [ "$condition" == "$line" ]; then
echo "$line"
break
fi
doneCode
x=10
(while :; do echo "$x"; x=$(( $x + 1 )); done) | while read line; do
if [ "256071" == "$line" ]; then
echo "$line"
break
fi
doneIn Contents-Read () how to read the last line of the standard output of the process ?
What code use to close or kill the process ?
Linux & Android enthusiast - France
Posted
Guru

Code (gambas)
- BuildForm
- Go
- TextArea1.Text &= sLine
- .Arrangement = Arrange.Vertical
- .Height = 500
- .Width = 300
- .Padding = 5
Posted
Regular

Code (gambas)
Edit : for more detail my need, I edit my first post with a concrete bash command.
Linux & Android enthusiast - France
Posted
Regular

In my view, what you need is to perform a dynamycal analyisis on the output of the console.
That is more difficult, since you need to know precisely if the output is something formatted as lines. Otherwise, you end up with an endless string which has only one line, which is always "the last line". So we're in a vicious cricle here: <COLOR color="#FF0000">what is "last line"?</COLOR>
If I understood it right, the first step would to direct the output from the console, into a string variable.
As an intermediate phase, you load it into a TextArea and get the image on how it looks like:
All you need here is a FMain module and a TextArea1 control.
To trigger the process, put a Button1 above the TextArea1, then on Button1_Click() event, call the procedure that does the Shell or Exec. Say…
Code (gambas)
- '---
- '--- Code for spying the console.
- '---
- GetConsoleOutput()
- '--- This goes into FMain.Class:
- '...
- TextArea1.Text=strConsoleOutput
- '--- Now, how does it look like? Do we have lines?
- '--- IF so, then we cycle through the lines, using a Stream, then a clause.
- '... stream Dim ,open etc.
- DoTheJobINeed()
- Else '--- We might need to do something here. Either ignore the line since we are missing what we are looking for, OR whatever else.
- DoTheAlternateJob()
In the code above, I admitted <COLOR color="#FF0000">by default</COLOR> that we got LINES. That is, more than one line, which is always "LastLine".
<COLOR color="#FF0000">NOTE:</COLOR>
I wrote the code in place from memory so YOU GOT TO TEST IT, and obviously, fill the required lines to catch the console output into the string [strConsoleOutput].
Since I hate console, I leave it up to you to write the appropriate code.
…
The other way around…
I have to figure out how to do this, because it goes beyond my understanding how you can test a string that is continuously generated and you want to find something in it, in real time. Meaning, as it is generated.
The other thing you need to do, is write the code for the Stream: to open it, read the lines from [strConsoleOutput] into [strCurrentLine] and test the [strToken]
As I said though, <COLOR color="#FF0000">maybe I got it wrong…</COLOR>
“The only thing necessary for the triumph of evil is for good men to do nothing.”― Edmund Burke;
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
Posted
Regular

I was not on the right the way. In Process_Read() we need to use Line Input instead of Read for that context.
Linux & Android enthusiast - France
Posted
Regular

That is the point:Philippe734 said
we need to use Line Input instead of Read for that context.
In the code I put there, and I mentioned "I SUPPOSED", the idea was to "Read Line", but the specifics of the output, were only a supposition.
Without a line formatted output, it's very difficult to "catch" a certain token, since the "one line" output is constantly changing.
If we have lines, it's easier, we can kill the process, once the token showed up. That spears CPU/RAM time.
The other approach, would require a loop (While/Wend) and reading recursively the current output, as it was generated at each iteration.
While the test condition is static, the test string changes continuously.
Problem is that I know nothing about how can you get out of the Shell/Exec the value of strOutput BEFORE the command ends. The test is otherwise, trivial.
… do whatever necessary
“The only thing necessary for the triumph of evil is for good men to do nothing.”― Edmund Burke;
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
1 guest and 0 members have just viewed this.


