Xcode 8.3: Run target with input from file - c++

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.

Related

C++ executable, sh 1:not found

I created a c++ programm that works with ros. The first step would be to open a roscore in a terminal and move on from there. I do so with system("roscore &");
I compiled my file and can run it just fine with ./file.
However, I want to be able to run it as an application (double click). I created a .desktop file and the program shows up in my application list. When i start it though, all I get is a terminal that opens with the message
sh: 1: roscore: not found
etc.
The same applies for the roslaunch commands. I also fork and exec a roslaunch command, which does not work as well.
I tried system("ls"); which worked. All cout messages work as well.
Any idea what is wrong here?
roscore executable is not located in std paths (/bin:/usr/bin:). Use the absolute path - system("/path/to/roscore &")

Setting up build command to get the runtime of C++ program in Geany

Is there any way that I can see the run time of my C++ program in Geany? I am trying to add a execute command like this "time(./%e<i.txt)" it is giving error
./geany_run_script.sh: 5: ./geany_run_script.sh: time(./g<i.txt): not found
I have i.txt in the same directory as output file.I just want to know the runtime of my C++ programs while taking input from .txt file without writing the commands every time in the terminal myself any way I can do this?

starting program via command line arguments

I'm trying to start a program via the command line. I am working out of section 8.5: Command Line Arguments in C++ for Everyone. I built the program in netbeans.
How do I start the program from the command line? I am not sure where to find the program. I was expecting to find an .exe in the Documents\NetBeansProjects folder that I could run with the arguments, but I could not find one.
I am on windows 7.
Thanks!
**Where does Netbeans output the C++ executable?
(in addition, I may or may not be able to figure out how to run it once I find it. ~never used cmd line before)
Alternatively, you can press [Win]+R and type/select cmd. For me, that's the fastest way.
There probably is some terminal under your OS. Try typing the full path of the executable in it.
To get a terminal, select start --> run --> enter cmd and press OK.
If "explorer" is still part of Windows 7, use that to search for the file. You can (or used to be able to run) explorer by pressing and holding the Windows key and then pressing the e key. From there, you can cd to the appropriate directory and enter the file name on the command line.

What needs to be done to get a distributable program from Eclipse?

I’ve produced a C++ program in Eclipse running on Redhat, which compiles and runs fine through Eclipse.
I thought that to run it separately to Eclipse you use the build artifact which is in the directory set via the project’s properties.
However this executable doesn’t run (I know it’s an executable as I’ve set it to be an executable via the project’s properties and it shows up as such via the ls command and the file explorer).
When attempting to run it using the executable’s name, I get the error:
bash: <filename>: command not found
When attempting to run it as a bash file:
<filename>: <filename>: cannot execute binary file
And when running it with "./" before the file name, nothing happens. Nothing new appears in the running processes and the terminal just goes to the next line as though I’d just pressed enter with no command.
Any help?
You've more or less figure out the first error yourself. when you just run <filename> , it is not in your PATH environment variable, so you get "command not found". You have to give a full or relative path when to the program in order to run it, even if you're in the same directory as the program - you run it with ./<filename>
When you do run your program, it appears to just exit as soon as you start it - we can't help much with that without knowing what the program does or see some code.
You can do some debugging, e.g. after the program just exits run echo $? to see if it exited with a particular exit value, or run your program using the strace tool to see what it does (or do it the usual way, insert printf debugging, or debug it with gdb)

Load a new exe with gdb

I am currently trying to make use of gdb to disassemble an exe, and from my home, I start the application like such:
gdb "c:\file.exe"
And gdb starts and loads that file automatically.
Now the problem is that from where I am atm, the command prompt is disabled and thus I cannot run the terminal window with the filename as the argument.
The only thing I think can do atm is open the gdb.exe file directly and then load the exe with a command or something, from gdb itself.
Is there a command I can use to load the exe to debug from within the application itself rather than passing it as an argument?
(gdb) <some command> "c:\file.exe"
(gdb)file c:\file.exe
To start debugging it , use the file command, as #Arkaitz Jimenez said
If your file.exe is a running process, you can use the attach command