Terminal Output Of Application Outside of Creator
-
I wish to see output statements in a Windows 10 desktop GUI application in a terminal when running in a release and debug builds outside of creator. The output statements work perfectly fine within Qt Creator.
I am running Qt 6.9.2 on MSVC2022 64bit with Cmake.
#include "mainwindow.h" #include <QApplication> #include <iostream> #include <QProcess> #include <QDir> #include <QDebug> int main(int argc, char *argv[]) { std::cout << "Standard output text" << std::endl; std::cerr << "Standard error text" << std::endl; QTextStream out(stdout); out << "Test Qtext"; QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }I have tried running QProcess's that would run concurrently to the application without success. Also, I have tried the recommended "Run in Terminal" option with and without enabling the internal terminal of Creator and both ways fail to show outputs. When I uncheck the "Run in terminal" option, my output is the expected text below.
Hello from standard output! Hello error message. Test QtextWould anyone have experience with this or have a hunch?
-
I wish to see output statements in a Windows 10 desktop GUI application in a terminal when running in a release and debug builds outside of creator. The output statements work perfectly fine within Qt Creator.
I am running Qt 6.9.2 on MSVC2022 64bit with Cmake.
#include "mainwindow.h" #include <QApplication> #include <iostream> #include <QProcess> #include <QDir> #include <QDebug> int main(int argc, char *argv[]) { std::cout << "Standard output text" << std::endl; std::cerr << "Standard error text" << std::endl; QTextStream out(stdout); out << "Test Qtext"; QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }I have tried running QProcess's that would run concurrently to the application without success. Also, I have tried the recommended "Run in Terminal" option with and without enabling the internal terminal of Creator and both ways fail to show outputs. When I uncheck the "Run in terminal" option, my output is the expected text below.
Hello from standard output! Hello error message. Test QtextWould anyone have experience with this or have a hunch?
-
@jsulm Thank you for replying. I have launched the application without any arguments from cmd and Windows Powershell not as an administrator without them displaying any output.
//Example Launches Without Output From cmd C:\Users\username\path> FrontEnd.exe C:\Users\username\path> start FrontEnd.exe C:\Users\username\path> start /B FrontEnd.exeLogs do display text when I launch the applications and redirect their output to a log. Logging is not an acceptable solution with the messages I wish displayed in runtime unfortunately.
//Launch With Redirected Output C:\Users\username\path>FrontEnd.exe > output.txtWhen I simply click on the executable through file explorer, no terminal pops up and there is also no output. However, there is no supporting QProcess that would launch another terminal, so I expect that. In Qt creator, I get output when I run with and without the internal terminal.
From this behavior, my hunch is that it is a really simple fix or something subtle. It seems the terminal either receives the output and does not display it either because it is not listening, I need to enable special permissions for a windows terminal in the program, or there is a blocker of some kind.
Would you have any ideas?
-
@jsulm Thank you for replying. I have launched the application without any arguments from cmd and Windows Powershell not as an administrator without them displaying any output.
//Example Launches Without Output From cmd C:\Users\username\path> FrontEnd.exe C:\Users\username\path> start FrontEnd.exe C:\Users\username\path> start /B FrontEnd.exeLogs do display text when I launch the applications and redirect their output to a log. Logging is not an acceptable solution with the messages I wish displayed in runtime unfortunately.
//Launch With Redirected Output C:\Users\username\path>FrontEnd.exe > output.txtWhen I simply click on the executable through file explorer, no terminal pops up and there is also no output. However, there is no supporting QProcess that would launch another terminal, so I expect that. In Qt creator, I get output when I run with and without the internal terminal.
From this behavior, my hunch is that it is a really simple fix or something subtle. It seems the terminal either receives the output and does not display it either because it is not listening, I need to enable special permissions for a windows terminal in the program, or there is a blocker of some kind.
Would you have any ideas?
@daviddev
You have a Windows "UI" program, i.e. linked as a "windows" rather than a "console" application.I think you will find: when a Windows UI application is launched, whether from a terminal or icon-shortcut, that stdout and stderr are attached to "nowhere", so anything written to them "disappears". If it works from
FrontEnd.exe > output.txtthat implies that the calling shell has redirected stdout to the file so it stays like that when it runs and you get output there.The stuff inside Creator with/without terminal is special code in Creator so that's different.
I am not sure what exactly you want to achieve for what situation(s). Logging to file sounds like a better option than stdout/err for a UI program anyway. Under Windows you might also try downloading something like dbwin, dbwin32 or whatever the modern replacement is and running that --- that displays any text sent via Win
OutputDebugString(), it may also capture some other stuff I'm not sure. Your program can also call Win32AllocConsole()to allocate a visible console window (like a terminal) and that will have stdout/err attached, instead of your attempted "supporting QProcess". Finally a UI program could create e.g. a permanently visible modeless dialog/window with, say, aQPlainTextEditin it to which you send all your output messages for it to display. -
D daviddev has marked this topic as solved on