如何将Qt控制台输出从命令行存储到文本文件中
How to store Qt console output into text file from command line in Ubuntu
我写了一个Qt应用程序,它在Ubuntu后台作为守护程序运行。这个应用程序在随机时间后崩溃,我想看看它崩溃时给出的错误。
我写这个语法是为了看看我是否能在文本中得到它的输出:
dimit@dimit-FX620DX:~$ ./Myapp &> DebugInfo.txt
,但它不会在文本文件中写入任何内容。我写了这个简单的程序来模拟更大的项目
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;
}
下面是我运行这段代码时的终端输出:
dimit@dimit-FX620DX:~/QtProjects/Test/Test-build-desktop-Qt_4_8_1__System__Debug$ ./Myapp &> DebugInfo.txt
Aborted (core dumped)
我期望在DebugInfo.txt文件中看到"Aborted (core dump)",但没有在其中写入任何内容。我该怎么办?
我在Ubuntu 12.04下使用Qt 4.8
程序不会打印"Aborted (core dumps)"文本,它是在程序终止后由shell 打印的。因此,解决方案很简单,在另一个shell中运行该程序,并将其输出重定向:
sh -c ./Myapp &> DebugInfo.txt
(-c
使shell作为命令行执行命令,这是必需的,因为没有它,sh
将尝试将./Myapp
作为shell脚本运行并失败。)
相关文章:
- 打印逐行存储的文本文件
- 将从格式化文本文件读取的文本数据存储到链表
- C++ 使用存储在动态数组中的文本文件中的数据查找模式
- 使用矢量将文本文件中的输入存储到 2D 数组中
- 是否保证相同内容字符串文本的存储相同?
- 从文本文件读取,然后将项目存储到列表中
- 从文本文件中读取一行并将其存储在 C++ 中的 2D 矢量中
- 如何将函数的输出数据存储在文本文件中
- 如何在不知道大小的情况下读取文本文件并存储到数组中
- 将文本文件中的文本存储到六个不同的矢量中(C++)
- 为什么使用 C++ 中的类对象写入文件中的数据以非文本格式存储?
- C++读取文本文件并存储数据
- 如何有效地读取和存储 1GB 文本文件中的数据
- 是否可以将来自 Win32 EDIT 控件的文本输入存储在C++ std::string 中?
- std::bad_alloc 将文本文件中的单个字符存储到矢量C++中时
- C ++将文本存储在数组的不同索引中,并带有一两个
- 在 c++ 中存储文本常量
- 最佳数据结构存储文本文件中的数字集
- 在C++中,使用什么数据结构来快速存储文本文件,该文件具有可变的行数和可变的子元素数
- 为文字处理器存储文本的更好方法是什么?