Start Command not allowing additional process to be created - batch-file

My Program opens a javascript server for listening. However when i run this in cmd
start "Runnning" /B CMD /C CALL "file\program.exe" 23 12
The Program is prevented from creating the process for the Javascript program. Any work arounds that work in (.bat) files are appreciated

Related

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

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

how to automatically close tinyweb console after running from batch file

I'm using TinyWeb server.
I run it using a batch file START_tiny.bat:
c:
cd\
cd tiny
cd bin
tiny c:\tiny\root 8080
exit
The problem is that after tiny.exe is executed, the console won't close so it hangs here:
I can manually close the console window, and it will continue to run as expected, but I was just wondering if there was a way in the batch file to make sure it closes after the program is invoked.
EDIT:
the solution was:
cmd /c start tiny c:\tiny\root 8080
The Windows command processor cmd.exe halts processing of the batch file as long as tiny.exe is running and waits for its termination, even if this application is a GUI application not opening any window or opening a GUI window.
The command exit is not necessary at all and is just bad for debugging the batch file.
It would be better to use a shortcut file (*.lnk) to just start TinyWeb server. Target in properties of shortcut file would be C:\tiny\bin\tiny.exe C:\tiny\root 8080 and Start in would be C:\tiny\bin or C:\tiny\root or whatever should be the current directory on starting TinyWeb. No console window is shown on tiny.exe not being a console application which I don't know as not having downloaded and installed this application.
The command start can be used in a batch file for starting TinyWeb server as separate process by cmd.exe without waiting for its termination.
One of the following command lines could be used in the batch file:
start C:\tiny\bin\tiny.exe C:\tiny\root 8080
start /DC:\tiny\bin tiny.exe C:\tiny\root 8080
start /D C:\tiny\bin tiny.exe C:\tiny\root 8080
start "TinyWeb server" C:\tiny\bin\tiny.exe C:\tiny\root 8080
start "TinyWeb server" "C:\tiny\bin\tiny.exe" "C:\tiny\root" 8080
start "TinyWeb server" /D"C:\tiny\bin" tiny.exe "C:\tiny\root" 8080
start "TinyWeb server" /D "C:\tiny\bin" tiny.exe "C:\tiny\root" 8080
Open a command prompt, run start /? and read the output help for an explanation of the above command lines.
The parameter /D specifies the start in respectively current directory for the started executable. It can be specified immediately after /D or separated with a space from the switch.
Command start interprets first string in quotes as window title. For that reason it is necessary to explicitly specify a window title in double quotes on one of the other arguments is enclosed in double quotes even if no console window is opened because of started application is a Windows GUI application. An empty title string specified with just "" is enough for GUI applications started by command start as separate process.
The command line cd /D "C:\tiny\bin" can be used to change current directory to C:\tiny\bin even on current directory being on a different drive. The help output on running in a cmd window cd /? explains the parameter /D to change also drive if necessary and not only current directory on current drive.

When opening vscode using batch file, cmd opens and doesn't close

When trying to open vscode folder using a batch file, Visual Studio opens up with that folder, but also a cmd window pops up and does not go away if you use exit command.
#echo off
start code "C:\GitHub\TestApp\testapp"
exit
VSCode opens up correctly, but also this window opens
Using VSCode 1.52.1, the only way I could start it without having a cmd window open after exiting the batch script is:
explorer.exe "%userprofile%\AppData\Local\Programs\Microsoft VS Code\Code.exe"
Note: it does not involve opening a specific local directory to work with. But maybe you can find a solution such as saving the folder as a workspace or using Ctrl+R to open recent folders. Plus, if you work only within that directory / workspace, or use it right before closing VSCode, it will be opened automatically at the next launch.
That's because you are actually invoking the batch file code.cmd which is located at [VSCodePath]\bin\code.cmd. The code.cmd file in turn invokes the actual VSCode executable code.exe
When invoking a batch file (.BAT or .CMD) using the start command, a new instance of CMD process will be created to handle the execution of the batch file, But it invokes the CMD process with the /K switch rather than /C
For example start code.cmd executes cmd /k code.cmd
It is the /K switch that causes the new cmd to remain open after finishing the execution of the batch file.
To resolve, instead of supplying the batch file directly the to the start command, execute it by an explicit CMD invokation:
#echo off
start cmd /C code "C:\GitHub\TestApp\testapp"
exit
That CMD window is associated with the VSCode instance that you just opened. Attempting to close it will terminate the application you started. (in this case, VSCode)
The start xxx xxx... command opens up a new cmd terminal to perform its action. Even though a new prompt appears, which can be used as a normal terminal itself, the VSCode process is inexorably linked to it as the parent process.
If your goal is to not launch a separate cmd window, then run:
start code /b "C:\GitHub\TestApp\testapp"
which just runs the command in the same window. The VSCode window is still inexorably bound to the current cmd window and will close if the cmd window disappears, but at least another cmd window isn't launched.
Windows doesn't have the capability to launch a program in the background from the terminal.
If all described solutions did not work for you, try making an ordinary Windows shortcut to "C:\Users\username\AppData\Local\Programs\Microsoft VS Code\Code.exe" C:\path-to-project-folder-or-file.
Then call this shortcut in your .bat or .cmd script like that (assuming shortcut name is shortcut):
#echo off
start C:\path-to-shortcut-file\shortcut

Tfs post-build step running application hangs

We have a configured TFS CI which is making our build. After a build I`d like to have my simple executable application to be deployed to specific folder on the server and then started.
I decided to do this with post-build step and batch script. Everything works perfectly except one:
when the application is stared, build agent(the one who runs my script) hangs.
Here is how I start my application from the script:
start /b %depldir%\MyApp.exe [params] > log.txt
So I start it in backgroound and redirect std out/error to file.
Application is started correctly but build process won`t finish untill I kill the application.
How do I start my application without build agent waiting for it to finish?
I'm not sure if this is a bug but if you use start /b something > logfile.txt the new and hidden cmd window is started with parameter /k. This forces the hidden window to stay active. This makes the calling bat wait for it to exit and this is why your build won't terminate. To verify this I've created two files:
starter.bat:
start /b tostart.bat > log.txt
tostart.bat:
echo started
When I start starter.bat the cmd doesn't terminate and in the task manager the following process appears:
cmd.exe USER 00 00:00:00 1.400k C:\Windows\system32\cmd.exe /K
tostart.bat
/K means:
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables (taken from http://ss64.com/nt/cmd.html)
To cut a long story short: it works fine when you replace start /b with call. Unfortunately call doesn't have a parameter like /b so your application won't start in background. I don't know whether this is a problem for you.
If it is: I've faced similar problems with my Jenkins build server. My solution was to create a task which runs my application (in background). Instead of calling the program itself I just call SCHTASKS /Run /TN "TASK_NAME". This command just triggers the task without waiting. This way you can also avoid problems with permissions etc.

TFS Auto Build hangs waiting for termination of BAT file

I have a TFS Build Definition.
In the work flow, I need to bring up a console listener, and run some tests on this listener.
So I create a BAT file with the followings:
start cmd /k "d:\abc.exe"
If I run this BAT file, the BAT itself will terminate, but it will spawn another cmd Windows, running the listener. So all is fine.
But when this is incorporated into TFS Build Definition, the work-flow would wait for the completion of this process, and the entire flow would hang.
I've tried with various switches for both START and CMD so that the work-flow can continue with the listener running, but to no avail.
start "" cmd /c "d:\abc.exe"
in cmd, /k means start a new instance, execute the indicated command and leave the window open. /c means is the same, but when command ends, cmd exits.

Resources