Tuesday, 15 February 2011

c++ - How to store Qt console output into text file from command line in Ubuntu -



c++ - How to store Qt console output into text file from command line in Ubuntu -

i wrote qt application runs in ubuntu background daemon. application crashes after random time, want see error gives when crashesh.

i wrote syntax see if can output in text:

dimit@dimit-fx620dx:~$ ./myapp &> debuginfo.txt

but doesn't write in text file. wrote simple programme simulate bigger project

mainwindow.cpp

#include "mainwindow.h" #include "ui_mainwindow.h" #include <stdio.h> #include <iostream> mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) { ui->setupui(this); std::vector<int> test; test[-1] = 90; //in here gives segmentation fault error , exits programme } mainwindow::~mainwindow() { delete ui; }

here output of terminal when run code:

dimit@dimit-fx620dx:~/qtprojects/test/test-build-desktop-qt_4_8_1__system__debug$ ./myapp &> debuginfo.txt aborted (core dumped)

i expected see "aborted (core dumped)" in debuginfo.txt file nil written in it. should ?

i'm using qt 4.8 under ubuntu 12.04

the "aborted (core dumped)" text not printed program, it's printed shell after programme terminates. so, solution simple, run programme in shell, , redirect it's output:

sh -c ./myapp &> debuginfo.txt

(the -c makes shell execute command command line, , needed because without sh seek run ./myapp shell script , fail.)

c++ qt ubuntu

No comments:

Post a Comment