Think about :I want to write a program use cmake auto compile some frequently library(zlib,png....and so on)
in cmd Console,I use .bat set up Environment.
sample :cmd /k "D:\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"
then cmake -G....cmake --build ....
Now I want Write a program(not .bat file),setup environment with .bat file.and then work as fine as in cmd Console.
(I can write a .bat file auto do it,but I want to write a exe do it.....)
No, that won't work. The batch file sets up the environment of that CMD process, not your executable.
Your batch file idea is the better solution, as it is run by CMD.
Related
https://github.com/ninja-build/ninja/releases
I have downloaded the ninja-win.zip folder and extracted it. When I open it, there is a single .exe file in the entire folder. When I double click it a cmd window flashes for a split second. I have also tried running it as administrator, but the same thing happens. What I don't understand is, what am I expected to do with this .exe file?
You must open a terminal (cmd.exe on Windows) and type something like ninja -f /path/to/buld/file. You may also wish to modify the PATH environment variable so that Windows knows where to find the Ninja executable, depending on your setup.
You can simple download ninja.exe file from this Link
https://github.com/ninja-build/ninja/releases
After that you just have to add the path to your ninja.exe file to your windows environment variables and then you can use ninja commands from anywhere in windows.
1. Open cmd in your Project Directory
2. There are guides on the internet on where to save the Ninja.exe so that it'll be callable in Cmd without specifying directory. Either follow them or:
i, Specify Directory when Calling Ninja. Putting "ninja" in Cmd actually calls Ninja.exe and is the same as something like "C:\users\user1\downloads\Ninja". or:
ii, Save Ninja.exe in the same directory as Project.
3. proceed with rest of the command.
Therefore the Final Command would be:
"C:\users\user\downloads\Ninja.exe" -f "D:\Projects\Project1"
In my work I use to invoke a lot of times cmake, building MSVS solutions. Each time I need to open a cmd line window and call cmake on my sources. I managed to create an alias to only write "cm ../source", which calls "cmake -G "Visual Studio 12" ../source".
I'd like to improve this process by adding an entry in the explorer's contextual menu.
I do not manage, only at once to call cmd.exe and execute "cmake -G "Visual Studio 12" ../source" or whatever : "cm ../source"
I read this very usefull topic
but I don't manage to pass arguments to cmd.exe and execute them :
This doesn't work:
cmd.exe /s /k pushd "%V"call "cm ../source" "%V"
Then I tried to execute a cmd file, and I manage to do it, but it's like to line inside wasn't executed and I don't understand why. My entry in the registry is :
cmd.exe /s /k pushd "%V"&call ".\cmake.cmd"
It correctly calls cmake.cmd (local file in my build directory) file which only contains:
and this executes the cmd file in an infinite loop that I don't understand :
My questions are :
Why this infinite loop. It acts like the file content wasn't executed.
Is there a better way to do without calling a separate file. I'd like to only invoke cmake without having this cmd file.
Thanks a lot :)
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.
I have recently installed MinGW to my computer, to compile and run programs written in c.
Right now I have to manually go to the bin-folder to execute and compile files.
The path is C:\MinGW\bin
Is there a a way to avoid this everytime? I want be able to directly write the commands when I open the command Line.
I tried to follow the Environment Settings on http://www.mingw.org/wiki/Getting_Started
but it does not work at all.
A simple solution would be a small batch script. Create a new batch file with this code:
#echo off
cd C:\MinGW\bin
:loop
set /p var=
%var%
goto loop
Could you show me your user environment variable called "path"? Maybe we will find the error there.
Edit:
Create a new environment variable in the upper field (user-environment variables). Enter this in the window which appears.
Name: PATH
Value: C:\MinGW\bin
This should work.
I have a bat to execute all files in a folder every 15 seconds. I need to make it .exe to run it as a hidden application.
I have converted it to .exe with bat to exe converter and other programs, and I see that in all of them, when I execute the .exe, for example, Load.exe, automatically start a cmd.exe at the same time. If I kill Load.exe it still continues to run, until I kill cmd.exe.
So, can I make an .exe from a .bat without depending on a cmd.exe?
Short but correct answer: no, you can not.
I don't know if it depends on CMD or not (probably it doesn't), but you can use C++ function system to execute each line of your .bat file.
Do it something like :
#include <stdlib.h>
int main()
{
system("<batch command goes here>");
return 0;
}
Simultaneously, you can add each line of .bat file to system function and execute it as a CPP/C program.