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.
Related
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.
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 &")
This is a weird one for sure.
If I open a command prompt window directly (searching cmd in start, right click > open command window here, cmd within bat file, etc....) all commands entered run perfectly fine.
If I open a command prompt window from within my C++ application (system("cmd"); or QProcess::startDetached("cmd"); etc....) the commands I enter throw errors.
Here are a few commands that don't work in the cmd opened from my app:
vssadmin delete shadows /all
vssadmin list shadows
wmic
shadowcopy
and so on... I get Class not registered and Initialization failure errors all around. Anything to do with shadow copies isn't working at all. But again, the weird thing is, those same commands work perfectly fine when cmd was opened traditionally (not from a program). Both instances of cmd have admin privileges.
So my question is, how come the way I open cmd affects whether or not some commands work? Everything I can see says there should be no difference.
32-bit applications running on WOW64 will be put under file system redirection. Therefore if your app is a 32-bit one, the call system("c:\\windows\\system32\\cmd.exe"); will be redirected to C:\Windows\SysWOW64\cmd.exe and 32-bit cmd will always be invoked. You have some solutions:
Use system("c:\\windows\\sysnative\\cmd.exe"); to access the real system32 folder and get the 64-bit cmd
Turn off file system redirection explicitly (should be avoided in general)
Or better compiling it as a 64-bit app.
I am running codeblocks on Linux Mint 17 and I have not had any issues until now. I am running a relatively long sequence of output and my terminal will only show the last 500 lines of output to Console (terminal). I am needing to view the beginnining portion of the sequence and I would like to know if there are any settings I could change within my OS or codeblocks itself to adjust the amount of output that is printed to console. Perhaps there is a way to save the console output to file (without coding for filestream)? Thank you! I appreciate your help greatly!
EDIT:
I forgot to mention I am using C++ and the console I am using is Linux Mint default terminal.
If you are using the terminal you could just ouput it to a text file like this:
./execution_file > text_file.out
The executable file should be in the same folder as the cpp file, but if you cant find it you could use:
g++ -o codefile.cpp executionfile
You can use less command in linux.
Ex : ./a.out (executable file) | less
In windows you have "more" command.
as like above linux command, you can pipe your output to "more" command and see full result.
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)