Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"I DO want your money, because god wants your money!" -- The Reverend Jimmy, from _Repo_Man_


devel / comp.lang.c / should I use popen() or QProcess to display output lines as they are produced?

SubjectAuthor
* should I use popen() or QProcess to display output lines as they are produced?Robert Magdziarz
+- Re: should I use popen() or QProcess to display output lines as theyThe Real Non Homosexual
+- Taking full advantage of "The First Response Effect" (Was: should I use popen() Kenny McCormack
`* Re: should I use popen() or QProcess to display output lines as they are produceScott Lurndal
 `* Re: should I use popen() or QProcess to display output lines as theyJames Kuyper
  `* Re: should I use popen() or QProcess to display output lines as theyKenny McCormack
   `* Re: should I use popen() or QProcess to display output lines as theyjames...@alumni.caltech.edu
    `* Topicality (Was: should I use popen() or QProcess to display output lines as theKenny McCormack
     `* Re: Topicality (Was: should I use popen() or QProcess to displayjames...@alumni.caltech.edu
      `- Re: Topicality (Was: should I use popen() or QProcess to displayKenny McCormack

1
should I use popen() or QProcess to display output lines as they are produced?

<12085b1a-18e3-4d93-b7a5-3cba9f04a3b9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16728&group=comp.lang.c++#16728

  copy link   Newsgroups: comp.lang.c
 by: Robert Magdziarz - Thu, 27 May 2021 17:21 UTC

I programmed PHP obfuscator in C++. There is command line program dirtyphp and GUI program dirtyphp-gui that calls command line program. GUI program uses Qt5. Both programs run in Linux and Windows. I want to display in GUI program output of command line program. I wrote:

bool get_line_from_pipe(const wchar_t *cmd, char buffer[MAX_LINE_FROM_PIPE]) {
static string cmdstr;
if (cmd != nullptr) {
cmdstr = shortwstr2str(wstring(cmd));
TRACE("cmdstr: " << cmdstr);
}
static FILE *pipe = nullptr;
if (cmd != nullptr) {
pipe = popen(cmdstr.c_str(), "r");
}
if (!pipe) {
throw runtime_error("popen() failed");
}
if (fgets(buffer, MAX_LINE_FROM_PIPE, pipe) != nullptr) {
TRACE("read " << strlen(buffer) << " chars");
return true;
}
pclose(pipe);
return false;
}

....
statusBar()->showMessage(tr("Please wait..."));
QApplication::setOverrideCursor(Qt::WaitCursor);
QString output = "";
char line[MAX_LINE_FROM_PIPE];
std::string pipe = dirtyphp_command.toStdString();
if (get_line_from_pipe(str2wstr(pipe).c_str(), line)) {
do {
output += QString(line);
ui->output_text->setText(output);
} while (get_line_from_pipe(nullptr, line));
}
QApplication::restoreOverrideCursor();
statusBar()->showMessage(tr(""));

The problem is that output is displayed when command line program finished running. I would prefer to display lines of output as they are produced, that's why I used popen(), not system(). Unfortunately GUI program receives output at the end of execution of command line program - I don't understand why. What's wrong with my code? Can I use popen() to achieve my goal or I must use QProcess from Qt5?

Re: should I use popen() or QProcess to display output lines as they are produced?

<a50f0dec-7001-4acd-a6b0-885cdf4ab92en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16729&group=comp.lang.c++#16729

  copy link   Newsgroups: comp.lang.c
 by: The Real Non Homosex - Thu, 27 May 2021 17:41 UTC

On Thursday, May 27, 2021 at 10:22:05 AM UTC-7, Robert Magdziarz wrote:
> I programmed PHP obfuscator in C++. There is command line program dirtyphp and GUI program dirtyphp-gui that calls command line program. GUI program uses Qt5. Both programs run in Linux and Windows. I want to display in GUI program output of command line program. I wrote:
>
> bool get_line_from_pipe(const wchar_t *cmd, char buffer[MAX_LINE_FROM_PIPE]) {
> static string cmdstr;
> if (cmd != nullptr) {
> cmdstr = shortwstr2str(wstring(cmd));
> TRACE("cmdstr: " << cmdstr);
> }
> static FILE *pipe = nullptr;
> if (cmd != nullptr) {
> pipe = popen(cmdstr.c_str(), "r");
> }
> if (!pipe) {
> throw runtime_error("popen() failed");
> }
> if (fgets(buffer, MAX_LINE_FROM_PIPE, pipe) != nullptr) {
> TRACE("read " << strlen(buffer) << " chars");
> return true;
> }
> pclose(pipe);
> return false;
> }
>
> ...
> statusBar()->showMessage(tr("Please wait..."));
> QApplication::setOverrideCursor(Qt::WaitCursor);
> QString output = "";
> char line[MAX_LINE_FROM_PIPE];
> std::string pipe = dirtyphp_command.toStdString();
> if (get_line_from_pipe(str2wstr(pipe).c_str(), line)) {
> do {
> output += QString(line);
> ui->output_text->setText(output);
> } while (get_line_from_pipe(nullptr, line));
> }
> QApplication::restoreOverrideCursor();
> statusBar()->showMessage(tr(""));
>
> The problem is that output is displayed when command line program finished running. I would prefer to display lines of output as they are produced, that's why I used popen(), not system(). Unfortunately GUI program receives output at the end of execution of command line program - I don't understand why. What's wrong with my code? Can I use popen() to achieve my goal or I must use QProcess from Qt5?

Both of these aren't covered by C. Try comp.programming

Taking full advantage of "The First Response Effect" (Was: should I use popen() or QProcess to display output lines as they are produced?)

<s8oqgs$1dpd6$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16732&group=comp.lang.c++#16732

  copy link   Newsgroups: comp.lang.c
 by: Kenny McCormack - Thu, 27 May 2021 19:05 UTC

In article <12085b1a-18e3-4d93-b7a5-3cba9f04a3b9n@googlegroups.com>,
Robert Magdziarz <robert.magdziarz.1972@gmail.com> wrote:
>I programmed PHP obfuscator in C++. There is command line program dirtyphp and
>GUI program dirtyphp-gui that calls command line program. GUI program uses Qt5.
>Both programs run in Linux and Windows. I want to display in GUI program output
>of command line program. I wrote:
....
> QApplication::setOverrideCursor(Qt::WaitCursor);

There is a bug in the Google Groups interface that makes it so that if you
post via GG, and you think you are posting to comp.lang.c++, the post
goes instead to comp.lang.c

Is that what happened here?

--
12% of Americans think that Joan of Arc was Noah's wife.

Re: should I use popen() or QProcess to display output lines as they are produced?

<3wUrI.452333$ST2.58791@fx47.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16739&group=comp.lang.c++#16739

  copy link   Newsgroups: comp.lang.c
 by: Scott Lurndal - Thu, 27 May 2021 21:51 UTC

Robert Magdziarz <robert.magdziarz.1972@gmail.com> writes:
>I programmed PHP obfuscator in C++. There is command line program dirtyphp =
>and GUI program dirtyphp-gui that calls command line program. GUI program u=
>ses Qt5. Both programs run in Linux and Windows. I want to display in GUI p=
>rogram output of command line program. I wrote:=20

>The problem is that output is displayed when command line program finished =
>running. I would prefer to display lines of output as they are produced, th=
>at's why I used popen(), not system(). Unfortunately GUI program receives o=
>utput at the end of execution of command line program - I don't understand =
>why. What's wrong with my code? Can I use popen() to achieve my goal or I m=
>ust use QProcess from Qt5?=20

While I haven't used QT, most graphics toolkits are event driven. Xt and GDK
have a mechanism that you can use to tell them to poll on a file descriptor
in the event loop and invoke a callback function when input is present on
the file descriptor.

The callback is called, the callback consumes the data from the file descriptor
and processes it (e.g. writing it to an output widget or dialog box). Then it
returns to the event loop (which then updates the screen to match the changes
caused by the callback function and handles asynchronous operations from the
display server).

Re: should I use popen() or QProcess to display output lines as they are produced?

<s8pmp9$kto$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16742&group=comp.lang.c++#16742

  copy link   Newsgroups: comp.lang.c
 by: James Kuyper - Fri, 28 May 2021 03:07 UTC

On 5/27/21 5:51 PM, Scott Lurndal wrote:
> Robert Magdziarz <robert.magdziarz.1972@gmail.com> writes:
>> I programmed PHP obfuscator in C++. There is command line program dirtyphp =
>> and GUI program dirtyphp-gui that calls command line program. GUI program u=
>> ses Qt5. Both programs run in Linux and Windows. I want to display in GUI p=
>> rogram output of command line program. I wrote:=20
>
>> The problem is that output is displayed when command line program finished =
>> running. I would prefer to display lines of output as they are produced, th=
>> at's why I used popen(), not system(). Unfortunately GUI program receives o=
>> utput at the end of execution of command line program - I don't understand =
>> why. What's wrong with my code? Can I use popen() to achieve my goal or I m=
>> ust use QProcess from Qt5?=20
>
> While I haven't used QT, most graphics toolkits are event driven. Xt and GDK
> have a mechanism that you can use to tell them to poll on a file descriptor
> in the event loop and invoke a callback function when input is present on
> the file descriptor.
>
> The callback is called, the callback consumes the data from the file descriptor
> and processes it (e.g. writing it to an output widget or dialog box). Then it
> returns to the event loop (which then updates the screen to match the changes
> caused by the callback function and handles asynchronous operations from the
> display server).
>

Two of the key concepts in Qt are what it calls "signals" and "slots",
which are special member functions. There are multiple ways to connect a
signal from a given object to a slot from an object, which will usually
be a different object. Connections can be made at compile time or at run
time, and they can be disconnected at run time. Whenever a signal is
emitted by a given object, all slots currently connected to that signal
for that object are called for the corresponding objects.

QProcess::readyReadStandardOutput() is a signal which get emitted
whenever the process has new data that arrived from the standard output
channel. There's a similar function that is emitted for standard error.

Re: should I use popen() or QProcess to display output lines as they are produced?

<s8q1ic$1eet7$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16743&group=comp.lang.c++#16743

  copy link   Newsgroups: comp.lang.c
 by: Kenny McCormack - Fri, 28 May 2021 06:11 UTC

In article <s8pmp9$kto$1@dont-email.me>,
James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
....
>QProcess::readyReadStandardOutput() is a signal which get emitted

Off topic.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Seneca

Re: should I use popen() or QProcess to display output lines as they are produced?

<b27b8648-335b-4398-a226-ecbd9de93769n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16751&group=comp.lang.c++#16751

  copy link   Newsgroups: comp.lang.c
 by: james...@alumni.calt - Fri, 28 May 2021 14:46 UTC

On Friday, May 28, 2021 at 2:11:35 AM UTC-4, Kenny McCormack wrote:
> In article <s8pmp9$kto$1...@dont-email.me>,
> James Kuyper <james...@alumni.caltech.edu> wrote:
> ...
> >QProcess::readyReadStandardOutput() is a signal which get emitted
> Off topic.

QProcess is one of the two options that mentioned in the Subject header
that the OP is asking for advice to decide between. No one can give him
useful advice on that question without knowing the advantages and
disadvantages of both options. How can discussion of one of those two
options be more off-topic than discussing the other one? This question
was posted to the wrong newsgroup - the popen() part of the question
should probably have been posted to comp.unix.programming. There don't
seem to be any Qt newsgourps - the best place to ask about QProcess
would probably be <https://forum.qt.io/>. But if you're complaining that
this is the wrong forum, your complaint would be more appropriated
posted as a response to the original message.

I've only used Qt for a total of about two or three years now, and I've
no actual experience with either popen() or QProcess, so I'm not really
in a position to provide much advice. However, by his own admission,
Scott Lurndal hasn't used Qt at all, so I know enough about Qt to
comment on the applicability of what he wrote to QProcess.

I will say that if I had Robert's problem, and the rest of the program
made no use of Qt, I would use it as an excuse to gain the experience
with using popen() that I currently lack. However, since he brought up
QProcess, there's a good chance that his program already uses Qt for
other purposes. If so, then there's a good chance that the popen() call
would occur inside the code for a member function of a class derived
from QObject, and that he would need to create Qt signals and slots
related to his use of popen(). That being the case, I'd recommend trying
QProcess, rather than popen(), since it looks like it should be more
convenient to use (at least in a context where Qt is already involved).

Topicality (Was: should I use popen() or QProcess to display output lines as they) are produced?

<s8rdbd$1f5eu$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16755&group=comp.lang.c++#16755

  copy link   Newsgroups: comp.lang.c
 by: Kenny McCormack - Fri, 28 May 2021 18:38 UTC

In article <b27b8648-335b-4398-a226-ecbd9de93769n@googlegroups.com>,
james...@alumni.caltech.edu <jameskuyper@alumni.caltech.edu> wrote:
>On Friday, May 28, 2021 at 2:11:35 AM UTC-4, Kenny McCormack wrote:
>> In article <s8pmp9$kto$1...@dont-email.me>,
>> James Kuyper <james...@alumni.caltech.edu> wrote:
>> ...
>> >QProcess::readyReadStandardOutput() is a signal which get emitted
>> Off topic.
>
>QProcess is one of the two options that mentioned in the Subject header

It is the :: that is O/T here (comp.lang.c). No such syntax in C.

See my first post on this thread, where I suggest that OP is posting via
Google Groups.

--
In Usenet, as in life, as you go through it, you will run into lots of nonsense.
Each time, you will have to decide from the following courses of action:
1) Argue with it or 2) Ignore it.
Experience shows that the later course is usually the best.

Re: Topicality (Was: should I use popen() or QProcess to display output lines as they) are produced?

<ee4f5ae2-a1cc-4ba4-ac79-1a8c926a2341n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16772&group=comp.lang.c++#16772

  copy link   Newsgroups: comp.lang.c
 by: james...@alumni.calt - Sat, 29 May 2021 05:11 UTC

On Friday, May 28, 2021 at 2:38:49 PM UTC-4, Kenny McCormack wrote:
> In article <b27b8648-335b-4398...@googlegroups.com>,
> james...@alumni.caltech.edu <james...@alumni.caltech.edu> wrote:
> >On Friday, May 28, 2021 at 2:11:35 AM UTC-4, Kenny McCormack wrote:
> >> In article <s8pmp9$kto$1...@dont-email.me>,
> >> James Kuyper <james...@alumni.caltech.edu> wrote:
> >> ...
> >> >QProcess::readyReadStandardOutput() is a signal which get emitted
> >> Off topic.
> >
> >QProcess is one of the two options that mentioned in the Subject header
> It is the :: that is O/T here (comp.lang.c). No such syntax in C.

The fact that there's no such syntax in C does not disqualify something from
being on-topic in this newsgroup. A question about a C function that is either
user-defined or standard-defined, asking whether it would be better to use an
alternative C++ solution, would be entirely on topic in either comp.lang.c or
comp.lang.c++; though it would be best to cross-post it to both groups.

popen() is not user-defined, it's defined by POSIX, which would make
comp.unix.programmer a more appropriate newsgroup than comp.lang.c for
this question, but you didn't say anything about that. The fact that QProcess is
part of Qt would make <https://forum.qt.io/> a more appropriate forum for this
question than comp.lang.c++, but you didn't mention that, either.

Why wait until my message before complaining about a lack of topicality that
was present in the original message?

Re: Topicality (Was: should I use popen() or QProcess to display output lines as they) are produced?

<s8ssjp$1fv94$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16774&group=comp.lang.c++#16774

  copy link   Newsgroups: comp.lang.c
 by: Kenny McCormack - Sat, 29 May 2021 08:05 UTC

In article <ee4f5ae2-a1cc-4ba4-ac79-1a8c926a2341n@googlegroups.com>,
james...@alumni.caltech.edu <jameskuyper@alumni.caltech.edu> wrote:
....
>Why wait until my message before complaining about a lack of topicality that
>was present in the original message?

Not the case. See my original, first post in this thread. The one where I
first raise the likelihood that this whole issue is a result of a well
known bug in the GG interface.

--
I voted for Trump because I thought he'd make pussy grabbing legal.
I honestly don't see any other way America could be made great again.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor