Can I run git shell and execute command from cmd? - batch-file

I would like to write a bat script that runs simultaneously Unity, visual studio and git shell. I would like to make git shell change directory (it always start at default github's repositories location), but I can't figure how.
so far, I've got something like that:
echo off
d:
cd D:\<path>\Visual Studio\Common7\IDE
start .\devenv.exe "C:\<path>\solution.sln"
cd D:\<path>\Unity\Editor
start .\Unity.exe -projectPath "C:\<path>\project directory"
c:
cd C:\Users\<username>\AppData\Local\GitHub\
start .\GitHub.appref-ms --open-shell //and now i need to execute "cd ../my project" on it

Related

how to run multiple command inside other terminal using batch file

i am using nvs, and there is a nvs command line using which i can change my node version.
currently i am using .bat file from Desktop and then go to nvs terminal
cd C:\nvs
start "C:\nvs\nvs.cmd"
this opens the terminal, and then i need to type more commands inside nvs terminal like
nvs use node/10.16.3/x64
cd ../code/api
node -v
code .
i need to automate this and all the executables to be part of the .bat file.
i tried using /c or /k to concatenate the commands. but the terminal closes before executing anything. how to run these commands as a part of batch file together.

Script that runs commands inside git bash - batch-file

I have a script that opens 2 git-bash terminals, but I also want to run 2 commands inside that script. Type of the file is .bat
cd "C:\Program Files\Git"
start git-bash.exe "--cd=C:\Homestead"
start git-bash.exe "--cd=C:\Users\user\Projects\first"
exit
I need a vagrant up and for the second one I need npm run watch. I tried to use echo but nothing happend.

OpenCMD, run .exe file and a command at same time

I am creating a script and I need to run exe file and a command at the same time. What am I doing wrong?
CD C:\Program Files (x86)\Jenkins\
START cmd.exe /T /C "jenkins.exe start"
The command line needs to be exactly as the following, otherwise it does not work:
C:\Program Files (x86)\Jenkins>jenkins.exe start
Thanks!
I don't quiet understand what you mean by saying you wan't to run an exe and a command at the same time. But if you wan't to start the jenkins.exe from your batch file, you can achieve this as follows:
cd "C:\Program Files (x86)\Jenkins\"
jenkins.exe start
alternatively, if you don't want the terminal to stay open as long as jenkins is running, you can use the following:
cd "C:\Program Files (x86)\Jenkins\"
start jenkins.exe start

how to run pass docker terminal commands using .bat file

I Want to invoke docker compose using bat file.I have tried to invoke using the following but its not executing the commands.
this is my .bat file
echo on
cd C:\Program Files\Docker Toolbox\
start start.sh cd desktop
cd test
docker-compose up
Is there any other way to execute docker commands using bat file.or any other file.
A batch file is a script file. A script needs an interpreter. For a batch file the interpreter is cmd.exe – the Windows command interpreter.
A *.sh file is also a script which needs an interpreter. The interpreter is on Unix/Linux systems sh, bash, ksh, ... which are also executables but without file extension .exe because on Unix/Linux executables usually do not have a file extension.
On Windows there is no interpreter installed by default for Unix/Linux shell scripts. If start start.sh works at all than because of having installed a shell interpreter on Windows which has been registered in Windows registry as application for opening *.sh files which means interpreting the commands in the shell script file by started application.
But commands in a batch script interpreted by cmd.exe and executed within a Windows command environment can't be executed in shell environment of the shell interpreter.
start start.sh starts a new process running parallel to the Windows command process created for execution of the batch file. The batch file processing immediately continues after this line with executing the next command in command process while the shell interpreter process interprets parallel the commands in start.sh.
So what you need here is a batch file which creates a shell script to call start.sh and executes other shell commands in shell environment by shell interpreter.
The batch code below might work. It is not tested by me as I don't have Docker Toolbox nor any shell interpreter installed on my Windows machine.
#echo off
set "ShellScriptFile=%TEMP%\%~n0.sh"
( echo start.sh
echo cd desktop/test
echo docker-compose up
) >"%ShellScriptFile%"
start "Docker Compose" /D"%ProgramFiles%\Docker Toolbox" /wait "%ShellScriptFile%"
del "%ShellScriptFile%"
set "ShellScriptFile="
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /? ... explains %~n0 (name of batch file without file extension and path)
del /?
echo /?
set /?
start /?
Read also the Microsoft article about Using Command Redirection Operators for an explanation of redirection operator > used here to create the shell script to execute with the 3 lines:
start.sh
cd desktop/test
docker-compose up
Those 3 lines are executed in the shell environment by shell script interpreter.
To run docker-compose via a bat file,
1. create a bat file eg run-docker-compose-up.bat
cd c:\docker
docker-compose up -d
pause
c:\docker is where I placed my docker-compose.yml
-d run containers in the background docker compose up docs
docker-compose must run as Administrator.
While a bat file itself cannot be marked as run as Administrator, you can either
right click on the bat file and choose 'Run as administrator'
or create a shortcut to the bat file and mark it as run as Administrator
(right click on shortcut, choose Properties, choose Advance, choose 'Run as administrator')
As I solved this problem, in a docker-compose case:
Go to your docker-compose.yml folder
On that, create a batchfile, such as: mydockerbatchfile.bat, using notepad (or other)
On this file, type your docker commands sequence', such as:
echo on
docker-compose down
docker container prune --force
docker system prune --volumes --force
docker image rm xxx/web-api
docker system df
docker image ls
pause
OBS: the commando pause will allow you check the results execution, in the screen)
Save -> make sure you saved in batch format/extension (mydockerbatchfile .bat)
In your windows desktop, create a ShortCut for the 'item 3 batch-file' (here - do not set the shortcut to "run as administrator")

how to start compass using a batch file

Hello can anyone tell me how I can start compass using a batch file?
cmd.exe /K "cd C:\Ruby200-x64\bin\ && C:"
compass watch "e:/project/html/"
But after it opens the correct location it does not start the line compass watch
Create a batch file (path\batchfile.bat) :
c:
cd C:\Ruby200-x64\bin\
compass watch "e:/project/html/"
Then execute :
cmd.exe /c "path\batchfile.bat"
Simple way which worked for me; have the batch file in the project folder with line:
compass watch
No need for changing paths if you move the project folder for example. For me it's convenient to just open the project folder and double click the file to start working.

Resources