(VS2010 C++) Execute a command every time the program is run? - c++

The IDE I'm using is VS2010 for writing C++
I want to execute the command cmd C:\utilities\unix\tail.exe -f -n15 $(ProjectDir)Log.txt every time the program I'm coding is run from within the IDE. (This command should open a console to track changes made to the file Log.txt)
There are ways to make a command run every time the program is built, but I can't find a way to make a command run whenever the program itself is run, even if it's already built. Where or how might I be able to set that kind of thing up?
I've tried putting $(TargetPath) & C:\utilities\unix\tail.exe -f -n15 $(ProjectDir)Log.txt into the project's Properties->Debugging->Command (TargetPath is the full name of the debug executable) but VS reads the entire thing as a filename and gets confused.

You can create a file run.cmd for example next to the vcxproj file, which would contain:
%1
C:\utilities\unix\tail.exe -f -n15 %2Log.txt
And then in Properties->Debugging->Command you write:
$(ProjectDir)\run.cmd
and in Command Arguments you write:
"$(TargetPath)" "$(ProjectDir)"
I may have misspelled the macros, but you get the idea: it executes first your program and then whatever you want.
Edit: Unfortunately it works only if you start without debugging (Ctrl+F5), because otherwise the debugger tries to attach to run.cmd and complains that the format is unsupported.

Related

Running C++ exe file in PowerShell

I'm usually not programming in C++, but this time I had to and I've got a problem executing my code in PowerShell (which I have never done before).
The program is written using CodeBlocks, it works fine. I specify arguments in Project_> Set program arguments and in does what it should, if no arguments are specified it returns an info about that, as it should.
The thing is, I built my program in CodeBlocks, then wanted to run the generated \bin\Program.exe' file in PowerShell. I enter:
C:\path\to\Program.exe
and nothing happens. I tried that with arguments, still nothing at all.
I fixed all missing .dll files, but I'm lost. Do I produce the .exe file in a wrong way? Is there any way to fix this issue?
First, make sure you're in the directory of the executable.
cd "C:\path\to\"
Then, execute the program as so:
.\"Program.exe"

How do I create a make file in windows operating system and run it using cmd

I am new to makefile concept
so to try out if I am able to run and compile c files using word "make"in command prompt I made main.c (which contains main function) ,ttt.c (which contain a function void ttt(int)) , mandar.h (headerfile to include void ttt(int) function in main.c)
when I run this program in cmd using "gcc main.c ttt.c -o main && main",program gets compiled and run properly(so there shouldn't be any error in code)
Now in the same directory I made a file Makefile.txt as follow
image of makefile
Now when I type "make "in cmd following message is shown
image of cmd message
I typed everything exactly the same way as in "head first c " book
did I miss something
this is my first time to ask a question so suggestion regarding improvement of questions are also welcomed
Its not Makefile.txt, you have to name it without any extension just Makefile.
Then run the command.
FIY make by default searches for Makefile in the current working directory. You can change this default behavior by typing make -f filename into the command prompt.
You create your Makefile with some editor (emacs, vim, perhaps notepad). Beware that tab characters are significant in that Makefile and most "action" lines in it should start with a tab, not several spaces.
You then type make in some terminal or command window.

How can I pass commands to the elevated application in a batch file?

I was wondering if anyone can help me. I'm currently working on a game engine project which involves its own c++ compiler. For this I'm "borrowing" the visual studio 2013 c++ compiler. everything works fine. The problem I am having is a cant figure out how I would pass commands to the elevated program in a batch file.
Let me Explain, right now I am using a program which calls the "vcvarsall.bat" file and passes in "x86" as a parameter. This is great for manual entry as it then allows me to input the commands to compile files. E.G "cl /EHsc <cpp files>"
As of now, when I add commands after I call "vcvarsall.bat", they just give me a command reference error saying the command is not recognized.
What I want to achieve is being able to call one bat file which executes and compiles all of my code for me. instead of having to manually type in the commands every time. This way the entire process is easier for the user.
Any help would be appreciated,
Thank you in advance!
when I add commands after I call "vcvarsall.bat"
Maybe it has been too long since I last did a batch file .. hope the following gets you started:
I think any .bat file will accept parameters, and internally, the .bat writer (i.e. you) uses special identifiers. Often they are named something like %1 and %2, etc. (some scripting languages use $1, and probably a few other approaches)
Without consuming these parameters in your .bat file, the command line interpreter tries to use the parameter as another command (so you get 'command not recognized')
Search all .bat files on your system for %1 (or $1 or whatever) ... maybe you'll find enough hints.
Thank you all for the help, the way I solved the problem was by finding the last batch file which was called and making the end of the file call another batch file in the main compile directory, this means I can programatically generate this batch file making it incredibly easy to generate custom compilations. thank you all,
Alister

Compiled exe won't run through my custom schemed cmd?

I have a custom color/font/size/etc. scheme for my cmd.
When I run my program through VS (with or without debugging) it runs my program in cmd using my scheme. (good)
But, when I run the exe file directly, it runs in the default cmd (without my scheme). (bad)
If I make a .bat file which executes my exe, then it runs in the schemed cmd. (good)
But if I make a shortcut of that .bat file, it runs in the default cmd! (bad)
How can I make it so that the exe itself runs through the schemed cmd?
If not possible, how can I make it so the shortcut to the exe/bat runs it through the schemed cmd?
If you want the software to run in schemed cmd, you should execute the program over command line, other way you can edit your program's font etc. in your program.
Compilers run programs by cmd.
And if you want it so much, you can check your program on task manager at beginning your code and if there isn't, you can run with system function and hide first one.
I don't know how you changed your cmd scheme, so, it is possible that this will not help you. Anyway...
The standard way of cmd customization is to include in HKCU\Console\ a subkey with the title of the console that will be customized, and inside this key, the values that define the console properties (more here)
So, let's say you have now a console scheme in the registry. When you start a console program via a shortcut, the window title of the started console is the text indicated as the shortcut name. Match shortcut name to console name defined in registry (or the reverse).

Matlab will not run my C++ .exe file

I have program in C++ that runs great but it has different steps in it. It opens a file first then does some calculations based on the data it gets from the file. Now I'm trying to run it through matlab. I tried mex but it got too complicated because I have VS 2010 Express and MATLAB 2007b. And so mex can never find my c compiler.
I'm now trying to just run it straight from the C++ program executable file. Here's how I tried to do it:
system('C:\path\file.exe')
it would run but the command window freezes and I have to close Matlab every time to get back on track. Then I tried to double click on the executable file it self. It flashes but I can see it outputs something from my file "file could not be uploaded" which is generated by a part of my program if it cant find the file.
So then I realized it's probably because of that that caused it to not run and crash.
So I wrote a sample code to open the file first before the system command open the .exe file. I've done something like fopen('fname','r'), but nothing works. Please note that this file I'm trying to open is a .COF file.
I tried running the .exe file using debug and release modes but nothing happens. It gives no errors which means it sees the .exe file but the command line doesn't come up and matland command window freezes.
After running, it's supposed to prompt the user at the command line then take input arguments and output something...
Please help....
I am guessing that your .COF file is in a different path than what's accessible by your binary. If you can recompile, try an absolute path name, and test it first without MATLAB.
There are more thorough ways to solve this, like passing the filename to your binary as a command line argument, or to read up what the rules are for the "current directory" when you use system, but perhaps you'd be happy with the quick solution.