this works:
main.cpp:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello world.\n");
}
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello world.\n");
}
To copy to clipboard, switch view to plain text mode
g++ main.cpp
./a.out > file
"file" now contains "hello world\n".
but this doesn't work:
main2.pro:
TEMPLATE = app
TARGET = main2
DESTDIR = .
CONFIG += release
SOURCES += main2.cpp
TEMPLATE = app
TARGET = main2
DESTDIR = .
CONFIG += release
SOURCES += main2.cpp
To copy to clipboard, switch view to plain text mode
main2.cpp:
#include <QCoreApplication>
#include <QString>
int main(int argc, char *argv[])
{
printf("hello world.\n");
return app.exec();
}
#include <QCoreApplication>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
printf("hello world.\n");
return app.exec();
}
To copy to clipboard, switch view to plain text mode
qmake
make
./main2 > file
now "file" is empty (after you ctrl-c to quit)
while
./main2
prints "hello world.\n" to the terminal.
Do I have to freopen because of QCoreApplication? Does it have to do with the ctrl-c which could be killing the program before it flushes the buffer?
thanks,
-chris
PS:
./main2 >file 2>&1
doesn't work either!
Bookmarks