bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libapl stdout


From: enztec
Subject: Re: libapl stdout
Date: Fri, 27 Jan 2023 14:28:29 -0700

Chris 

i don't have qt installed nor do i have your
#include "aplexec.h"

On Fri, 27 Jan 2023 11:23:08 -0500
Chris Moller <moller@mollerware.com> wrote:

> For what it's worth, in an ongoing project in use:
> 
>     #include <QtWidgets>
> 
>     #include <iostream>
>     #include <sstream>
> 
>     #include <apl/libapl.h>
> 
>     #include "aplexec.h"
> 
>     LIBAPL_error
>     AplExec::aplExec (apl_op_e apl_op, QString &cmd,
>                QString &outString, QString &errString)
>     {
>       LIBAPL_error execerr = LAE_NO_ERROR;
> 
>       switch(apl_op) {
>       case APL_OP_EXEC:
>         {
>           std::stringstream outbuffer;
>           std::streambuf *coutbuf = std::cout.rdbuf();
>           std::cout.rdbuf(outbuffer.rdbuf());
>           std::stringstream errbuffer;
>           std::streambuf *cerrbuf = std::cerr.rdbuf();
>           std::cerr.rdbuf(errbuffer.rdbuf());
>           execerr = apl_exec (cmd.toStdString ().c_str ());
>           std::cout.rdbuf(coutbuf);
>           std::cerr.rdbuf(cerrbuf);
>           outString = QString (outbuffer.str ().c_str ());
>           errString = QString (errbuffer.str ().c_str ());
>         }
>         break;
>       case APL_OP_COMMAND:
>         {
>           std::stringstream errbuffer;
>           std::streambuf *cerrbuf = std::cerr.rdbuf();
>           std::cerr.rdbuf(errbuffer.rdbuf());
>           const char *res = apl_command (cmd.toStdString ().c_str ());
>           if (res) {
>             outString = QString (res);
>             free ((void *)res);
>           }
>           std::cerr.rdbuf(cerrbuf);
>           errString = QString (errbuffer.str ().c_str ());
>         }
>         break;
>       }
> 
>       return execerr;
>     }
> 
> I.e., I'm capturing stdout and stderr in strings.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]