I have a react application and I start it with the following .bat file:
cd..
cd projects
cd material
cd server
npm run dev
When the script runs, it opens cmd, and runs my app, which shows up in chrome.
I searched the whole day, but I didn't find anything for killing the program and closing the batch file by closing the browser.
Is there any way to do this, at all?
Did you try? Just put it last line on your bat file.
exit
Related
The issue
I am trying to create a batch file that will execute the following two commands:
cd /some/path
dotnet run
that produces the following output:
It starts my localhost server.
Trying To Accomplish
What I would like to do is, put those two commands in a batch file and automatically open Chrome to the server address, HOWEVER, the dotnet command takes some time to finish. So somehow, I would have to keep monitoring localhost to see if it is available.
Any help would be appreciated. Although opening a CMD window, typing those 2 commands, and waiting a minute isn't all that much of a problem, it sure would be nice to just click on a batch file.
Thank you.
You can create a batch file like this code :
#echo off
Set "ApplicationPath=%UserProfile%\source\repos\PruttPos\PruttPosSystem\"
CD /D "%ApplicationPath%"
dotnet run
Start "Chrome" Chrome.exe "http://localhost:5000"
pause
I have a batch file that copies files from and to an external hard drive. I wanted to add a section at the end of the script that would automatically eject the hard drive so it could be safely removed. I did some research and found that Remove Drive is my best option. I have it set up to use and working. I can write a bat file
#echo off
RemoveDrive :E -L
and it works perfectly!
However, I've hit a snag. When I add this exact line (well without the #echo off) to the end of my bat file, it fails to eject. My guess is that its the same problem as when you've got files open from a usb drive and try to eject it. It won't work because the system is using it. I tested this by creating a seperate bat file that ran just the RemoveDrive named it "RemoveDrive.bat". I then added to the end of my batch file:
pause
call "RemoveDrive.bat"
When the script hit the pause command. I tried to run the batch file by simply clicking the icon. The eject attempt failed. I pressed any key to continue and the called bat file failed and the script (and cmd window) closed. I then double clicked the icon for "RemoveDrive.bat" and it worked.
So after that long explanation, I was wondering if anyone had any suggestions for how to work around this. I was thinking if there was a way I could use the call function with some sort of delay and could close the cmd window. If I could get the cmd window to close and then have the bat file run automatically, I'm betting that would work.
I am trying to launch an Android emulator from a batch file inside my build definition, with the next command:
start /WAIT "Start Emulator" "C:\Program Files (x86)\Microsoft Emulator Manager\1.0\emulatorcmd.exe" launch /sku:Android /id:97522427-7A5E-4F3B-96A8-B9F9F0C0423A
I tried to add the build step as a command line, and a batch script.
Problem: The script is working right, and opening the emulator and wait for it to fully open, but once script finishes executing and console closes, the emulator is closing as well.
I tried to run the script directly on build server, and it works fine without closing emulator, but when queued as a build step, I am facing the above problem.
Question: How can I force the emulator to stay open after batch file finishes executing?
EDIT:
It looks like the build definition task terminates all processes it created in the defined step, I have tried multiple script, tried cmd /k and tried the /b and tried to create another batch file that actually calls this one or start it, yet no results. I am still waiting for any possible solution.
Alright, I tried a lot of scripts in batch files, and I tried to run it from command line, after a lot of time waste and getting tired, I decided to give PowerShell task a try to fix my problem. I ended up with this:
Start-Process -FilePath "C:\Program Files (x86)\Microsoft Emulator Manager\1.0\emulatorcmd.exe" -ArgumentList "launch /sku:Android /id:97522427-7A5E-4F3B-96A8-B9F9F0C0423A" -Verb runas
Start-Sleep -s 60
This made the emulator start, and stays running even after PowerShell script ends.
I'm doing a batch file to unify all the Phonegap commands to create an app. All seems work well, but after the command phonegap create appName my cmd stops the batch script and doesn't continue working. I suppose that Phonegap's commands finish with an "exit" or similar, but I'm not sure.
Does someone know if there is any way to run this commands in a batch file without this problem? Is there any way to return the control to the batch script?
Thanks!
Try this:
call phonegap create appName
I tried using CALL to start Google Chrome then immediately return control to the console, but it wasn't returning to the console. (Windows 7, not in command prompt but using a *.cmd file)
I solved the case by using START:
START "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
I am trying to create a batch file, to launch my app with one click on Windows. I have:
cd "C:\Users\<project_dir>"
venv\scripts\activate
python __init__.py
start /d "C:\Program Files (x86)\Google\Chrome\Application\" chrome.exe localhost:5000
Problem 1: Although venv\scripts\activate works manually, it does not work in the batch file (I've also tried start /d).
Problem 2: launching the Flask server with python __init__.py causes the batch script to pause, so that the browser is never launched.
This should work:
cd "C:\Users\<project_dir>"
start venv\scripts\python __init__.py
start /d "C:\Program Files (x86)\Google\Chrome\Application\" chrome.exe localhost:5000
I have addressed your problem #1 by using the virtual environment directly, without activating it. You can also do call venv\scripts\activate and then invoke your script with start python __init__.py.
The problem #2 is solved by running the server via start so that it spawns a new process.