How can I view what the output of commands such as cout is in the terminal when executing an application?
For example, if I have an application named application.app, in order to run it from the terminal what I do is type open application.app
This launches the app correctly but I am unable to see the output of the print statements that are in the code.
To see the program's stdout output in Terminal, you can run it instead like this:
./application.app/Contents/MacOS/application
Related
I am running VSCode in Ubuntu to debug a C++ program. Debugging a console app with GDB is working fine except I really want to capture the console log output to a file. I cannot see a way or option to do this. Is there any option to capture this console log output?
Since there does not seem to be a native feature to save the output of a VSCode terminal, maybe you can use in said terminal a command allowing you to save that session.
See for instance "Gdb print to file instead of stdout"
gdb core.3599 -ex bt -ex quit |& tee backtrace.log
As mentioned, the output is written to backtrace.log and also on the screen.
As the OP Andy Tomlin mentions in the comments, this is not compatible with a debugger session.
We solved the problem by just handling it inside the app and redirecting cout internally to a file.
I wrote a simple C++ program that requires some input to run. In the terminal I simply run in ./myProgram < fileWithData.txt. However I could not figure out how to specify and input file for the target executed in Xcode. I used the command line project. Of course I could use a different target, for example run Terminal.app and then pass it the executable with the input file but then I can no longer debug it.
This question: Cannot get lldb to read file input explains how to set the input path in lldb, but I could not find a way to specify lldb commands that are executed before the process is started.
I don't think there's a way to do this entirely from within Xcode. However if you set the Run Scheme in Xcode to the launch mode "Wait for executable to be launched," hit run, and then run your program from Terminal.app with the appropriate piping, the Xcode-embedded lldb will connect to it.
My application runs different bash files when i run my application under QTCreator everything works fine but when i run my application directly i cant read the QProcess output . even when i run my application via Terminal it works fine , so where is the problem ?
i'm using QT 5.7 / OSX Platform
here is my code
QProcess proc ;
proc.start(QCoreApplication::applicationDirPath() + "/check.sh");
proc.waitForFinished();
QString output = QString(proc.readAll());
qDebug() << output ;
There are some possibilities you should investigate
Can you confirm that scripts are running though when you run it standalone?
QProcess always was a little skittish about creating processes when supplied scripts, depending on platform. Does script have shebang in it? Does it match the shell you're running your program from? You may need to create process based on shell, supplying script's file name as a parameter.
QProcess::readAll() May return nothing if output buffer wasn't flushed by the process. Outputting EOL at end would force the flush.
I want to create a GUI for GDB debugger, so I need a way to run GDB debugger in terminal and execute commands in that and also get output from that on user triggered events on my screen in ubuntu. how can I do that for such a program?
it tried
int main(){
system("gnome-terminal 'gdb test'");
system("break main");
return 0;
}
but it executes the command on the terminal not on the gdb program
Each of the system() calls opens a separate shell. So these are independent of each other.
If you want to continuously communicate with a child process, rather use popen() please.
I am using the Remote Deploy feature of Qt Creator to launch my simple command line application on an embedded Linux target board. My test application is extremely simple and asks the user to print his/her name. It crosscompiles, transfers to the board, and launches and the 'Application Output' window near the bottom of Qt Creator shows the 'Type your name:' prompt, but I cannot type anywhere and provide stdin to the application running remotely through Qt Creator.
How can I accomplish this within Qt Creator? Can I somehow manipulate the deploy 'arguments' to connect a device to provide stdin to my command line app? I also cannot launch the application remotely by checking the 'run in terminal' checkbox under Projects > Run Configuration since it is not available for remote deployments.
Code:
#include <iostream>
using namespace std;
int main() {
cout << "Enter a number: ";
int nb;
cin>>nb;
cout << "Here is your number:" << nb << endl;
return 0;
}
Application Output in Qt Creator:
Killing remote process(es)...
Starting remote process ...
Remote process started.
Enter a number: d
I found out that there is no way to provide stdin to an app launched by qt creator from within the IDE.
I did try a few things and it looks like a named pipe works just fine. Luckily it’s included with Busybox so it’s on my board.
To use it you launch the app remotely from Qt Creator using the ‘Alternate executable on device’ option under ‘run settings’
and pipe the last line of the named pipe to your c++ program expecting stdin. So your ‘Alternate executable on device looks like:
cd /home/test; tail -f mypipe | ./test3 –qws
‘test3’ is my program and /home/testis the location of the executable.
Then open up 1 extra ubuntu terminal and SSH to the board. Now create a named pipe called ‘mypipe’:
mkfifo mypipe
And when your program expecting stdin launches and waits for input, you can echo the input from that
other terminal into the named pipe and your program will take it as stdin:
echo ‘2’ > mypipe
There are more options in Debug > Start Debug submenu. And there's one that you need: Attach to Running Debug Server. It does open this neat little window:
As you can see, there's a lot of parameters, even "Run in terminal" option, but it doesn't work on my machine for some reason. Don't forget to properly set your local path to executable binary and kit device settings. I would also recommend you to bind hotkey for AttachToRemoteServer command in Environment > Keyboard settings.
After that the only thing you need to do is to run gdbserver on your remote device:
gdbserver :<port> <executable>
Running process does have a proper stdin and stdout streams and you can interact with your application in terminal via SSH session.