[Interest] Redirect stdout to a file
Yifei Li
yifli82 at gmail.com
Wed Jul 3 17:56:26 CEST 2013
Hi Scott,
The following is a minimal example which will reproduce my problem. On my
Mac, once I kill the GUI, 'ping' also disappears.
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QProcess>
#include <QStringList>
int main(int argc,char* argv[])
{
QApplication myApplication(argc,argv);
QMainWindow w;
w.show();
QStringList parameters;
parameters << "google.com";
QProcess* myProcess = new QProcess;
myProcess->start("ping", commandAndParameters);
return myApplication.exec();
}
On Tue, Jul 2, 2013 at 3:10 PM, Scott Aron Bloom
<scott.bloom at onshorecs.com>wrote:
> Windows and Linux… I don’t know if it detatches on linux..****
>
> ** **
>
> I just know that if I manually kill the UI while the CLI version is
> running, Ill have to track it down in the task manager later..****
>
>
> Scott****
>
> ** **
>
> *From:* Yifei Li [mailto:yifli82 at gmail.com]
> *Sent:* Tuesday, July 02, 2013 6:54 AM
>
> *To:* Scott Aron Bloom
> *Cc:* interest at qt-project.org
> *Subject:* Re: [Interest] Redirect stdout to a file****
>
> ** **
>
> Hi Scott,****
>
> ** **
>
> I'm working on a Mac. How about you? OS probably matters.****
>
> ** **
>
> Yifei****
>
> ** **
>
> On Mon, Jul 1, 2013 at 11:30 PM, Scott Aron Bloom <
> scott.bloom at onshorecs.com> wrote:****
>
> Yes that is exactly what I do.. ****
>
> ****
>
> *From:* Yifei Li [mailto:yifli82 at gmail.com]
> *Sent:* Monday, July 1, 2013 7:29 PM****
>
>
> *To:* Scott Aron Bloom
> *Cc:* interest at qt-project.org
> *Subject:* Re: [Interest] Redirect stdout to a file****
>
> ****
>
> Hi Scott,****
>
> ****
>
> What I'm trying to do is exactly the same as what you did. ****
>
> ****
>
> Can you confirm the following is how you made it? In my experiment, the
> following way makes the newly created process terminate when the GUI
> crashes. ****
>
> ****
>
> QProcess *proc = new QProcess;****
>
> connect(proc, SIGNAL(readyReadStandardError()), this SLOT(readStderr()));*
> ***
>
> proc->start();****
>
> ****
>
> Thanks,****
>
> ****
>
> Yifei****
>
> ****
>
> On Mon, Jul 1, 2013 at 6:28 PM, Scott Aron Bloom <
> scott.bloom at onshorecs.com> wrote:****
>
> Im completely confused on what you are trying to do..****
>
> ****
>
> I can tell you that, I have a QProcess variable, and I have attached to
> the “stdout/stderr available signals”.. When they trigger, I get the stdout
> and stderr****
>
> ****
>
> And if the GUI crtashes while the CLI call is running, the CLI keeps
> running.****
>
>
> Scot****
>
> ****
>
> *From:* Yifei Li [mailto:yifli82 at gmail.com]
> *Sent:* Monday, July 01, 2013 3:21 PM****
>
>
> *To:* Scott Aron Bloom
> *Cc:* interest at qt-project.org
> *Subject:* Re: [Interest] Redirect stdout to a file****
>
> ****
>
> So is there a way to achieve what I want? -Yifei****
>
> ****
>
> On Mon, Jul 1, 2013 at 6:15 PM, Scott Aron Bloom <
> scott.bloom at onshorecs.com> wrote:****
>
> Yes, calling proc.startDetached still calls the static version****
>
> ****
>
> *From:* Yifei Li [mailto:yifli82 at gmail.com] ****
>
> *Sent:* Monday, July 01, 2013 2:53 PM
> *To:* Scott Aron Bloom****
>
> *Cc:* interest at qt-project.org****
>
>
> *Subject:* Re: [Interest] Redirect stdout to a file****
>
> ****
>
> I just tried, and it does not work. Redirection only works if
> 'proc->start()'. -Yifei****
>
> ****
>
> On Mon, Jul 1, 2013 at 5:39 PM, Scott Aron Bloom <
> scott.bloom at onshorecs.com> wrote:****
>
> Yes… ****
>
> ****
>
> ****
>
> ****
>
> *From:* interest-bounces+scott.bloom=onshorecs.com at qt-project.org [mailto:
> interest-bounces+scott.bloom=onshorecs.com at qt-project.org] *On Behalf Of *Yifei
> Li
> *Sent:* Monday, July 01, 2013 2:25 PM****
>
>
> *To:* interest at qt-project.org
> *Subject:* Re: [Interest] Redirect stdout to a file****
>
> ****
>
> Hi Scott,****
>
> ****
>
> Are you suggesting something as follows? ****
>
> QProcess proc;****
>
> proc.setStandardOutputFile();****
>
> proc.startDetached();****
>
> ****
>
> Yifei****
>
> ****
>
> ****
>
> ****
>
> On Mon, Jul 1, 2013 at 5:08 PM, Scott Aron Bloom <
> scott.bloom at onshorecs.com> wrote:****
>
> If the goal, is to redirect stdout/stderr, and not have the call block
> (static startDetached).****
>
> ****
>
> You can still use the NON-static version of the start method****
>
> ****
>
> Scott****
>
> ****
>
> *From:* interest-bounces+scott.bloom=onshorecs.com at qt-project.org [mailto:
> interest-bounces+scott.bloom=onshorecs.com at qt-project.org] *On Behalf Of *Yifei
> Li
> *Sent:* Monday, July 01, 2013 1:58 PM
> *To:* interest at qt-project.org****
>
>
> *Subject:* Re: [Interest] Redirect stdout to a file****
>
> ****
>
> I guess dup2 needs to be called by the process, correct? But I can't
> change its src code. - Yifei****
>
> ****
>
> On Mon, Jul 1, 2013 at 4:42 PM, Guido Seifert <wargand at gmx.de> wrote:****
>
>
> If it is only Linux you could use dup2.
>
> Windows? No idea.
>
> Guido****
>
>
>
> On Mon, 1 Jul 2013 16:31:19 -0400
> Yifei Li <yifli82 at gmail.com> wrote:
>
> > Hi folks,
> >
> > I know this can be done using QProcess::setStandardOutputFile.
> >
> > However, I need to start my process using the static function
> > startDetached, and still want to be able to redirect its stdout/stderr to
> > another file.
> >
> > Any suggestions?
> >
> > Thanks,
> >
> > Yifei****
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest****
>
> ****
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest****
>
> ****
>
> ****
>
> ****
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest****
>
> ****
>
> ** **
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130703/7e270a2c/attachment.html>
More information about the Interest
mailing list