2

I wrote a Qt application which runs in Ubuntu Background as a Daemon. This application crashes after a random time, I want to see what error it gives when it crashesh.

I wrote this syntax to see if I can get its output in a text:

dimit@dimit-FX620DX:~$ ./Myapp &> DebugInfo.txt

but it doesn't write anything in the text file. I wrote this simple program to simulate the 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 it gives segmentation fault error and exits the program
}

MainWindow::~MainWindow()
{
    delete ui;
}

here is the output of the terminal when I run this code:

dimit@dimit-FX620DX:~/QtProjects/Test/Test-build-desktop-Qt_4_8_1__System__Debug$ ./Myapp  &> DebugInfo.txt
Aborted (core dumped)

I expected to see "Aborted (core dumped)" in the DebugInfo.txt file but nothing were written in it. What should I do ?

I'm using Qt 4.8 under Ubuntu 12.04

5
  • 2
    You want to forward the standard error of your process to a file, not the standard output. That means 2> instead of > Commented Jun 21, 2014 at 9:59
  • 1
    yeah but putting & before > means both standard output and standard error. Commented Jun 21, 2014 at 10:06
  • Remove spaces between &> and DebugInfo.txt and i would use it in that order >& Commented Jun 21, 2014 at 10:06
  • @Dimitry Hm, interesting, didn't know that one. I thought you want to execute it as a job and forwarding the output to a file. Commented Jun 21, 2014 at 10:14
  • @Maciej it didn't change anything ... I think bash handles white spaces. Commented Jun 21, 2014 at 12:38

1 Answer 1

1

The "Aborted (core dumped)" text is not printed by your program, it's printed by the shell after program terminates. So, solution is simple, run the program in another shell, and redirect it's output:

sh -c ./Myapp &> DebugInfo.txt

(The -c makes the shell execute the command as a command line, and is needed because without it sh would try to run ./Myapp as a shell script and fail.)

Sign up to request clarification or add additional context in comments.

1 Comment

Now I can understand why users with high reputation has more ability to solve the problems than others ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.