QProcess read only last line (linux)



  • I'm on ubuntu 14.04 qt5.6....

    I try to read only last line of m_myprocess1 ....
    I've m_myprocess2 and m_myprocess3 too..... fflush is not a solution because flush all stdout and in my case i need see first response for other process ... and in any case not work in my code..

    I write a sequence of separate command in m_myprocess1 and at every command I receive a response ..... I must read every response to check error .....

    I set m_myprocess1 to textmode .... in these way i can get txt response that can parse ....

    for me isnt possible use ```
    m_myprocess1->waitForFinished(-1);

    so I use```
    m_myprocess1->waitForFinished(50);
    

    with qbytearray and qtesxtstream is possible to use readallstdout or readline but:
    -readallstdoutput return all standard output .....
    -readline read all line .....

    For me is the firs time on these things (read a single line of QProcess) ... there is a way to do these??

    regards
    gfxx


  • Moderators

    You can use readAllStandardOutput() and parse the output to find what you need.



  • there are multiple line with same world ... if i parse all I obtain 100 or more result......

    thanks for reply
    gffx


  • Moderators

    You can split the string using new line character and then just take the last line.



  • yes ... I can but the resul iare in any case 100 or more result .... I'm able to read single line with terminator but all the line have a terminator and is not possible flush the first output.

    Regards
    gfxx


  • Moderators

    Your title " QProcess read only last line (linux)" says you need the last line. If you split the string using new line character then the last line will be the last entry in the resulting string list.



  • perhaps I' m not expressed myself well .... when I ask reply stdout may also contain 1000 lines .... on its answers can not insert characters and if you do the parse it takes me too long .... I have a cycle time of 50-33usec ..... the process is a communication telnet .... I almost believe it is good to me recreate the telnet communication using qt .... so would provide an answer for once .....

    for explain me better attach an example of output... using readallstdout is more then these, using readline is these....

    "get error\n"
    "ERROR OK\n"
    "set mycommand1\n"
    "get error\n"
    "ERROR OK\n"
    "set mycommand2\n"
    "get error\n"
    "ERROR OK\n"
    "set mycommand3\n"
    "get error\n"
    "ERROR OK\n"
    "ERROR OK\n"
    "set mycommand2\n"
    "get error\n"
    "ERROR OK\n"
    "set mycommand3\n"
    "get error\n"
    "ERROR OK\n"
    "set mycommand2\n"
    "get error\n"
    "ERROR OK\n"
    "set mycommand3\n"
    "get error\n"
    "ERROR OK\n"
    "ERROR OK\n"
    "set mycommand2\n"
    "get error\n"
    "ERROR OK\n"
    "set mycommand3\n"
    "ERROR OK\n"    <------ last line but how can get ONLY THESE???
    

    someone have some experience about? in the past I try with normal socket sistem but the server (that send response and accept command) not reply my correcly .... because the socket client isnt telnet client ....

    regards
    gfxx



  • is possible to use | tee command if using telnet communications via qprocess and then read the output file deleting every new row after reading .....


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.