Writing Batch file that monitors a certain web page's status - batch-file

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

Related

How do I stop my batch file and pushd from referencing the unc when opening cmd.exe?

I'm trying to run a batch file from a local Windows server that calls on computers in my domain to pull from the shared folder and run an exe. I'm not sure if my script is trying to do too much or too little.
So I run the below batch locally
X:\pstools\psexec.exe \\Computer -d -u DOMAIN\user -p password -i \\SERVER\test\testfile.bat
and testfile.bat:
#echo off
pushd \\SERVER\test\
call program.exe
popd
When I run the script, psexec runs and I get a confirmation that testfile.bat was started on target computer. On the targeted computer nothing happens. If I navigate to the share on the targeted computer and run testfile.bat, I get "CMD.EXE was not started with the above path as the current directory.UNC paths are not supported. Defaulting to Windows directory." From there the computer runs the called .exe with no issues.
If I target this towards another server in my domain it executes perfectly, but not on domain computers. I thought maybe a GPO issue, but I can't find a solution.
Thanks for any knowledge or help provided!
Thanks for all the tips everyone! This is how I ended up getting it working for anyone who might have the same issue.
Script on Server:
x:\pstools\psexec.exe \\Computer(or text file with computers listed) -d -s cmd /c (batchfile.bat)
Similiar to what I was trying before, but to ensure you run the command line as System on the remote PC you have to specify "-s cmd". The /c copies the batch to the remote system to run locally. You can include a "-f" to overwrite if you've already copied it previously. I just put the batchfile in the pstools folder.
Batchfile.bat:
pushd \\networkdrive
call (.bat/.cmd/.exe/etc.)
popd
I disabled the firewall for testing, but I believe you have to open TCP-445/UDP-137 for PSEXEC. Otherwise, that's it. Super simple solution.

VSTS, Launching Android emulator from a batch file not working as expected

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.

.bat Script Terminating Before AWS Auto Scaling Commands Executed

I am fairly new to Amazon Cloud Auto Scaling (and AWS all together).
I am currently trying to write a .bat script that will automatically create a launch configuration and then an auto scaler. The aim is for an image that was previously set up about a week ago by a coworker.
The problem I encounter is that when I run the script, no commands past the launch configuration command is executed.
The code is here:
echo Beginning Auto Scale Up Process
REM Create a launch config
as-create-launch-config --image-id ami-xxxxxxx --instance-type t1.micro --user-data "Created by Launch Config reportingServerScaleUp-lc" --launch-config reportingServerScaleUp-lc
echo Timer Complete
I am looking for suggestions to help me debug this issue. Or advice on how to solve it. After the "echo Timer Complete" I have a command to create an auto scaler. Though, not even the "echo Timer Complete" is executed. The console does return indicating that the launch configuration is created though :)
Also, when I enter each command sequentially into the command line, each executes perfectly. The launch configuration is created as is the auto scale group.
It turns out that the AWS commands call exit which exits the .bat script prematurely.
Prepending each AWS command with "call" did the trick.
I found suggestions in this question: Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

How to start two servers (mysqld and thin) in one batch file?

I want to create a batch file to start MySQL server (mysqld) and Rails Thin server (rails s thin). But only MySQL starts, rails s thin doesn't:
#ECHO OFF
cd C:\path\to\app
CMD /C "mysqld --console"
REM exit <-- with or without it
REM cd C:\path\to\app <-- with or without it
CMD /C "rails s thin"
I also tried to create three files for this. The main one runs other two. Doesn't help either, only MySQL runs. And I need to start MySQL before Rails. Rails needs running MySQL. How to write such a batch?
UPD:
How to start 2 programs simultaniously in windows command prompt
use start
e.g.
start notepad.exe
start calc.exe
if you want to run one after another with some tests, you may need to write your own program.

How to create a .BAT file opening program and preventing it from opening new windows?

So I am starting a consol program from .bat file. I want it to run as a process but not showing any windows. How to do such thing?
I think the start command with a '/B' option should do it ...
Windowless:
#echo off
start /B Myapp.exe
Minimized:
#echo off
start /MIN Myapp.exe
I'm not sure if I understand what you mean: if you run a console program from a .bat/.cmd script, that program will use the existing console window, not create a new one.
I suspect what you're really asking is how to prevent Explorer from opening a console window for the .bat/.cmd script itself. There's no built-in way to do that (although as amir75 suggested, you can mitigate it by running the script minimized; instead of running the script directly, create a shortcut to it and edit the shortcut's properties).
Alternatively, you can run your script through the silentbatch program that Paul Miner and I wrote.

Resources