【发布时间】:2014-08-11 23:44:12
【问题描述】:
我编写了一个 Qt 应用程序,它作为守护程序在 Ubuntu 后台运行。此应用程序在随机时间后崩溃,我想看看它在崩溃时给出了什么错误。
我写了这个语法来看看我是否可以在文本中得到它的输出:
dimit@dimit-FX620DX:~$ ./Myapp &> DebugInfo.txt
但它不会在文本文件中写入任何内容。我写了这个简单的程序来模拟更大的项目
主窗口.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;
}
这是我运行这段代码时终端的输出:
dimit@dimit-FX620DX:~/QtProjects/Test/Test-build-desktop-Qt_4_8_1__System__Debug$ ./Myapp &> DebugInfo.txt
Aborted (core dumped)
我希望在 DebugInfo.txt 文件中看到“已中止(核心转储)”,但其中没有写入任何内容。我该怎么办?
我在 Ubuntu 12.04 下使用 Qt 4.8
【问题讨论】:
-
您希望将进程的标准错误转发到文件,而不是标准输出。这意味着
2>而不是> -
是的,但是把 & 放在 > 之前意味着标准输出和标准错误。
-
删除 &> 和 DebugInfo.txt 之间的空格,我会按这个顺序使用它 >&
-
@Dimitry 嗯,有趣,不知道那个。我以为您想将其作为作业执行并将输出转发到文件。
-
@Maciej 它没有改变任何东西......我认为 bash 可以处理空格。