MSysGit - run bat files directly - windows

I installed new version of MSysGit and now I am not able to run *.bat files directly from command line("called MINGW64").
I try to search it, but I only saw options which needs run cmd first.
Out of a git console: how do I execute a batch file and then return to git console?
cmd "/C clean.bat"
Is there some option to just run the clean.bat?
Thank you very much
I solve that by updating all libraries... Maybe Cygwin? I am not sure, but update all your software and it works.

Try this from MINGW command line
$ cmd <test.bat

Try this from MINGW command line
$ eval "./test.bat"
D:\workspace>echo hello world
hello world

Related

How can I run a batch-file under windows git-bash console?

How can I run a batch-file uder windows git-bash console.
When I run it I get:
user#DESKTOP-DF012sh MINGW64 /c/project-folder
$ util.bat
bash: util.bat: command not found
It should work if you mention where the bat is.
./util.bat
By default, a $PATH does not include the current folder.
I just tested executing a .bat script that way, and it worked just fine.

How do I write a batch file that opens a msys shell and then run commands in the shell?

I'm trying to automate the process of building ffmpeg on Windows 10. I'm following the guide here: https://trac.ffmpeg.org/wiki/CompilationGuide/MSVC
Everything works fine when I do it manually, however I want to write a batch file that I can run to go through the entire process automatically.
Building requires me to set up the Visual Studio environment and the MSYS environment. This is where I'm having trouble, since running the MSYS environment opens up a new shell. I want to pass the configure/make/make install commands to the MSYS shell after it is opened.
I've tried the solution here: How to open a new shell in cmd,then run script in a new shell?
The problem they had looks similar to mine, but the solutions posted there didn't work for me.
Here is the bat file currently:
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\vcvars64.bat"
call "C:\workspace\windows\mingw-get\msys\1.0\msys.bat" start cmd.exe /k bscript
pause
and bscript:
./configure --enable-shared --toolchain=msvc --arch=amd64
make
make install
I've tried all sorts of variations like:
call "C:\workspace\windows\mingw-get\msys\1.0\msys.bat" /k bscript
call "C:\workspace\windows\mingw-get\msys\1.0\msys.bat" bscript
start "C:\workspace\windows\mingw-get\msys\1.0\msys.bat" /k bscript
start "C:\workspace\windows\mingw-get\msys\1.0\msys.bat" bscript
And I've also tried leaving the bscript code in the original batch file.
The configure/make commands will either run in the original cmd window, a new cmd window or wont run at all.
Is there a way to pass commands to the MSYS shell like that?
This might be considered somewhat of a late answer but in the spirit of helping out those who come along here in the future:
The MSYS2 documentation contains a page specific to launching MSYS2: https://www.msys2.org/wiki/Launchers/
From there, we learn that one can launch an MSYS2 environment from a Windows shell like this:
C:\\msys64\\usr\\bin\\env MSYSTEM=MSYS /usr/bin/bash -li
If you place this in a *.bat file and execute the script, a new terminal window will spawn with bash running under the MSYS2 environment.
The documentation further illustrates how to run something within that bash shell:
C:\\msys64\\usr\\bin\\env MSYSTEM=MSYS /usr/bin/bash -lc python
The above would again spawn a new terminal window, load the MSYS2 environment, launch bash and then run the python executable in that bash instance.
From here, either directly run the program you want to (instead of python) or create a bash script and pass the parameter to that script to the bash invocation to execute a regular bash script within the MSYS2 environment from a Windows Batch file :)
I'm not sure if you get the result.
you can run command in windows console:
"C:\msys64\msys2_shell.cmd -mingw32 -shell test-script"
Command & paramerter comment:
C:\msys64\msys2_shell.cmd : msys launching bat
-mingw32 : arch, I use the 32bit
test-script : the startup script in /usr/bin
And you need to set the $PATH in startup script to launch your command

How to run shell script on Teamcity Windows agent?

We used to use Jenkins as our CI tool, I can run shell script in Jenkins windows slave, the steps is:
1.install cygwin on Windows slave
2.add step in Jenkins as shell script
3.add "export PATH=/cygdrive/c/dev/tools/cygwin/bin:$PATH " as the first line
then I can execute any shell script in Jenkins.
Now we need to move to teamcity, and I found above steps not work on teamcity.
when I run a "Command line" and set the first line as "export PATH=/cygdrive/c/dev/tools/cygwin/bin:$PATH", it gives me an error as "'export' is not recognized as an internal or external command".
Is there any way to resolve it? I don't want to re-write our shell script into cmd.
This is quite easy to resolve. The error does not come from Cygwin of course, but from CMD. The export command only makes sense within a Bash script; cmd has no way of knowing what to do with it.
What you need to do is simply specify to CMD that the script should run using Cygwin's command interpreter (bash). So you can either just specify the long path to the bash executable and your script, as in
C:\dev\tools\cygwin\bin\bash D:\myscript.sh
or you can just add the path to the cygwin directory to your machine's PATH variable. You can do this by changing the System Settings and append the path there, or you can do it as part of your script above:
# this is not necessary if you have already changed the System Variable to include the path
set PATH=C:\dev\tools\cygwin\bin;%PATH%
bash D:\myscript.sh
There is a good chance you already have Git installed on the agent with Git Bash. Following is how I run npm commands without changing the PATH variable
"C:\Program Files\Git\bin\bash.exe" -c "cd Source && npm install && npm run build"
With this, you can run the shell/bash commands:-
"C:\Program Files\Git\bin\bash.exe" -c "cd Source && npm install && npm run build"
And from Powershell, if you want to run bash scripts :-
& 'C:\Program Files\Git\bin\bash.exe' .\build.sh

'touch' is not recognized as an internal or external command, operable program or batch file

I work with laravel 5 , when i type in windows cmd this command
"touch storage\database.sqlite"
this error message rise
'touch' is not recognized as an internal or external command, operable program or batch file.
any hint to solve it ?
if you are using node.js just use npm to install it on Windows with this command:
npm install touch-cli -g
it will install the command line interface for touch, you can then use it the same as unix...
Fixed after running this command:
npm install touch-cli -g
After that I can run this:
touch .babelrc
The command you're trying to run is a unix/linux based command so it won't work in Windows.
All it does is update the modified timestamps of a file.
There's another question on here that gives you an alternative for Windows: https://superuser.com/questions/10426/windows-equivalent-of-the-linux-command-touch/764716
You have to install Touch CLI, Run below command in CLI
npm install touch-cli -g
You can just use echo> in windows cmd
i.epath/file.sqlite
If you are on windows device just install git bash and type the following command
touch test.html.
The above command will generate a zero kilobyte test.html file for you in your specified directory.
It is applicable to any other type of file.
If you are trying to use TypeScript in ReactNative first run:
npm install touch-cli -g
and then you can use touch, example:
touch rn-cli.config.js
ex:
type nul >test.html in windows CMD & another one ways is
echo.>test.html
both are working 100% fine
Just run it through the GitBash terminal on windows and it works fine
Incase anyone is trying to use the 'touch' command from windows to configure Typescript for a React Native app, or anything else. It works for me by running the 'touch' command either from git bash or by downloading the WSL and running it from there.
You can type the same cmd in git bash in the folder where you want your compose file.
, used with copy to indicate missing parameters. This updates the files
modified date. E.G. copy /b file1,,
I use this syntax in cmd. So far it is working well without installing something.
type nul > (filename)
In my case, I used
type nul > index.js // for creating an empty Javascript file.
If all the solutions above still dont work for you. Try this:
If you already have Git installed, then you also have GIT BASH installed too... To solve this problem navigate to your project directory using the GIT BASH Terminal and try again using touch Procfile. It should work perfectly.
I was reading a solution in the GitHub community and it's effective for me.
If you are using VSCode and you would like to do something like Linux you can use git bash and it works the same. You can add git bash into VSCode by the following:
File -> Preferences -> Setting ( Or Ctrl + , ).
Now, looking the top right and choose the icon "Open Settings (JSON)".
Add this to the last of the Setting file:
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "C:\\Program Files\\Git\\bin\\bash.exe"
},
},
"terminal.integrated.defaultProfile.windows": "Git Bash"
Finally reopen the VSCode and open the git bash terminal in your VSCode.
Notice: Make sure you have already installed Git Bash. Good luck!
You may be using PowerShell. The team helped me Add-Content.
Link to the page
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-content?view=powershell-7.2&viewFallbackFrom=powershell-7.1
Example: Add-Content -Path .\Test.txt //Test.txt - name of file
run this code in cmd then Finish:)))))))
npm install touch-cli -g

MSYS error "rem: command not found"

I am getting this error "rem:command not found" in my batch file. Other dos commands (e.g. echo) are also not found.
My makefile is calling this batch file. This works previously when I am using cygwin. But when I changed to MSYS, I am getting this error. Anyone know why this is?
I am using MSYS version 1.0.17 on a Windows pc. But, I did not install Mingw. Should i install it also?
It looks as though you are trying to run a "Batch" file using Bash. This will not work. While Batch file interprets rem as a comment, Bash simply thinks it is a command and tries to run it.
My suggest would be to rewrite it as a Bash script, perhaps this could be a starting point.
After trying with cmd //c [path_to_bat file] it works for me.
This is because mingw cannot run *.bat file directly after running *.bat file with cmd it works.
I found following mail thread about this type of issue
https://lists.gnu.org/archive/html/help-gnu-emacs/2003-10/msg00323.html

Resources