How to run multiple commands (each from a new terminal) from a batch file in Windows - windows

I've been using Ubuntu all my life, but today I've been given a different machine installed with Windows 10. I've an Angular project and I want to do the following things. All these in a separate terminal:
Navigate into project folder and run code . so that I can see the code on Visual studio.
Navigate into project folder and run ng serve to launch my application and keep it running.
Navigate into project folder and run node server.js to start backend server and keep it running.
this is very painful as the project location is-
C:\Users\tanzeel\Downloads\social-coder
Navigating again and again with a new terminal is what wasting my time. I decided to write a batch file so that I can do all at once with one single click. This is what my starter.bat file contains:
cd C:\Users\tanzeel\Downloads\social-coder\application 2>nul && call npm.cmd start
node C:\Users\tanzeel\Downloads\social-coder\server\server.js
code C:\Users\tanzeel\Downloads\social-coder
All of the above 3 commands works perfectly If I manually copy-paste them in separate terminals. But when I try to run them from batch file the problem is only first command is executed.I don't know other two are simply ignored or what. I'm coming from:
How to run multiple commands in a batch file?
How to run multiple commands in one batch file?
I admit that I'm a newbie and there are gaps in my knowledge. Please correct me.

You need to use e.g. START to spawn new processes, otherwise the currently running program will just block until it's finished. It looks to me that this is what you want:
#ECHO OFF
CD C:\Users\tanzeel\Downloads\social-coder
START code .
CD application
START npm start
CD ..\server
START node server.js
EXIT

Related

Opening several MacOS terminals and running a command on each tab

Every time I get to work I have to startup 6 local servers. It would be amazing to have one script that starts up these processes in their respective tab.
So it would come done to something like:
echo 'Starting server'
open new tab
cd to directory (ex. /project company/back-end/server))
run startup command (ex. node server.js)
I'm quite new and the examples with bash or applescript didn;t work for me.
BTW: there's an space in the cd directory names, I read that it's different then?

need help in running a bat file but only after restart (log off/on not included)

i have a certain program that i want to run as windows boots up
but! i need it to be only after windows restart not log off and log on are out of the question - the system i have is running tests and and the app that i want to run is canceling those tests that`s why i need it to run only after windows restarts , so there is no chance that a tests would fail because of it
the .bat file points to the location of
tried shell:common startup but that open the .bat file even after i log off or log on
how do i do this ? i need this to be in a script/.bat file as well
You should add it here
C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
But cause you mentioned after only restart then you will need to run an background script to handle that restart
Or we may..
The common command to restart windows via .bat or cmd file is shutdown -r
So we can create
reboot.bat ,script.bat ,mover.bat > for example in 'C:\test' directory
reboot.bat
move script.bat "C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\script.bat"
shutdown -r
script.bat
: : stuff here..
C:\test\mover.bat
mover.bat
move "C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\script.bat" script.bat
now that we have our scripts let's add them to our Environment variables
From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables.
In the section System Variables, find the PATH environment variable
and select it.
Click Edit then add ; following by C:\test Click Ok, Ok etc and
restart your cmd if opened
To answer your question just type reboot.bat or reboot in CMD command-line
Which when you want to run your script after restart you have to type this to cmd or just..make a restart.bat file with this command for just one click
I used stack overflow for android to answer this without test cause i'm not windows but i'm just familiar with plus didn't have my PC at this moment but i hope that answer is clear and understandable

Execute WIndows bat file in Jenkins

I am using Jenkins 2.46.1
I have a build pipeline plugin installed and I want to execute a Windows batch file in it. The batch file should execute in a new command window and not on jenkins console output. I give the below Jenkins pipeline groovy script:
node {
stage 'Init'
bat '''
call C:\\myprj\\mybat.bat stop
EXIT /B 0
'''
stage 'Deploy'
bat '''call C:\\myprj\\mybat.bat'''
}
In the init stage, I want to kill the process if it is already open and in stage deploy it should open a new command window and run my batch file.
The problem is that the above does not work. The build is succesful but no command window opens up. Pls suggest
Technically, to do what you're asking you should be able to run
bat 'start cmd.exe /c C:\\myprj\\mybat.bat'
This will launch a new command windows (cmd.exe) and run the batch file given. Depending how your Jenkins slave is running you may not see anything. (eg if it's running as a windows service or different user, you won't see anything)
Alternative solution if the agent is running in a service and you would like to get output:
bat(readFile("mybat.bat"))
Note: The bat file will need to be in your workspace.
Additional Note: You are no longer running the bat file from its original location. Instead it is being run from a temp location created by the underlying durable task system. This means things like %~dp0 in your script are not going to return the paths you might expect.

run curl from windows task scheduler automatically

I have a simple one line bat file that runs a curl localhost:port. My curl.exe is in the same folder as the bat I don't have it installed globally. It runs fine if I double click it, it also runs fine if I right click in task scheduler and select run task. It also says it completes the "scheduled tasks" successfully but nothing happens (I'm sure of this as I'm checking data that should update if the script is run, and it doesn't happen under the scheduled/automatic scenarios). After reading lots of users issues I tried configuring in two ways (all on 5 minute updates):
Common Way
Action: Start a Program
Program/script: C:\p\updater.bat
Start in: C:\p\
Other Way
Action: Start a Program
Program/script: cmd
Add arguments: /c start "" "C:\p\updater.bat"
I have set permissions to the bat and the containing folder to allow all for all users/etc. Neither work when automatically triggered, neither error. I've tried in Server 2008 and Windows 10 (my OS) mode. Both work if I right click run task, neither automatically, any ideas?
Default working directory for scheduled script is %Windows%\system32. Try to add in first line to you updater.bat:
cd c:\p\
For diagnostic, you can add output redirect to you commands in bat file:
echo Script Started >> c:\p\log.txt
curl SomeCommand SomeCommand >>c:\p:\curloutput.txt
echo Script Ended >> c:\p\log.txt
and check files log.txt and curloutput.txt after execution of your script

when I run mongod --config "C:\Program files\MongoDB\Server\3.0\bin\mongodb.config" it repeats endlessly

mongod --config "C:\Program files\MongoDB\Server\3.0\bin\mongodb.config"
I don't know what else to say... I am startled and frustrated because that's something I've never seen before. Usually when there's error you get some message that you can analize and make it right. But I hit Enter and the line I typed gets looped and it looks like if I would press arrow-up key and Enter subsequently, except I don't. After a while I have to stop this and press ctrl + c to kill the job. Have anyone seen this behaviour? I am on windows 7 64bit.
Mongod.exe is in C:\Program files\MongoDB\Server\3.0\bin\ and this folder is in my PATH.
That happened today first time when I run the command from webstorm built-in terminal. When I run it in cmd it gets executed normally BUT when i put the command in .bat file and try to execute it - same sh*t happens even in cmd. ? I wish I would never switched back to Windows.
Your batch file is calling itself (remember that in windows the current active directory is implicitly included in the list of folders to search for executable files)
Rename the batch file to something different to mongod.bat or mongod.cmd or change the reference to the program to execute from mongod to mongod.exe. Any of this changes will avoid the batch file to call itself.

Resources