So I tried exit and I tried putting a 2 second delay before exit but neither worked. After the bat file successfully runs, the CMD window will stay on.
I did notice however that a CMD window pops up and disappears right away and then the empty CMD window just stays there. (It's like there are two CMD windows)
#echo off
cd C:\Program Files\obs-studio\bin\64bit
"C:\Program Files\obs-studio\bin\64bit\obs64.exe" --collection Replay, --profile Replay, --scene Scene, --startreplaybuffer --minimize-to-tray
exit
EDIT: Also removing the cd line doesn't make the batch file work. I'm not sure why.
The window doesn't close because calling an app directly will tell the batch execution to wait for the app to close before running the next line. Use Start instead. So your batch will be :
#echo off
cd C:\Program Files\obs-studio\bin\64bit
start "" "C:\Program Files\obs-studio\bin\64bit\obs64.exe" --collection Replay, --profile Replay, --scene Scene, --startreplaybuffer --minimize-to-tray
The exit is superfluous since after the end line it should close anyway. By the way if you're just looking to create something to click/call for launching OB studio with those parameters, using shortcut should be enough (put C:\Program Files\obs-studio\bin\64bit on Start In and write the whole command and parameters on Target)
Related
I have a problem in my jenkins job and I isolated into one command. So I created another separate job to try to fix it.
So in this job, called "teste" I only have one single command:
start cmd /k call "C:\Program Files\myDir\myBat.bat"
This opens a separate cmd window running my bat file, which should keep running "forever".
But the problem is when I do it, my jenkins job keeps stuck into a "exit 0" operation that I have no idea from where it came from.
Thats the console:
[EnvInject] - Loading node environment variables.
Building remotely on Machine01 in workspace C:\workspace\teste
[teste] $ cmd /c call C:\...dir\jenkins.bat
C:\workspace\teste>start cmd /k call "C:\Program Files\myDir\myBat.bat"
C:\workspace\teste>exit 0
Then it keep stuck at that point.
Example of myBat.bat content:
echo hi
pause
There's any way to make this call in another window without waiting for its finish?
I solve my problem changing the way I was calling my other .bat, calling it through powershell. But since I was from a bat file, I used the command to send a powershell command, calling my other bat file.
Also, I've added another line changing the jenkins BUILD_ID to a fake one, so it doesn't kill it.
So I changed from this line:
start cmd /k call "C:\Program Files\myDir\myBat.bat"
To this :
set BUILD_ID=dontKillMe
powershell -Command "Start-Process 'C:\Program Files\myDir\myBat.bat'"
I hope it helps someone someday.
I'm trying to open two VSCode projects from a batch file, and then close the batch file and let the VSCode run.
Tried several methods:
This does not close the batch file, and if I close it by my self, VSCode terminates:
start "" "C:\Program Files\Microsoft VS Code\Code.exe" c:\project1
start "" "C:\Program Files\Microsoft VS Code\Code.exe" c:\project2
exit
This one opens two cmds, each one opens VSCode and then terminates, but often it also holds and does not close for some reason:
start cmd /c "code c:\project1 && exit"
start cmd /c "code c:\project2 && exit"
Simply running VSCode sometimes holds the execution of the next commands altogether:
code c:\project1
code c:\project2
.
. <-- Next commands don't run
.
So how should I open VSCode in a way that will not stop the execution and will not depend on the terminal remaining open?
I know this topic is more than 2 years old now, but I was facing this problem right now and just found out the solution.
Try calling code.exe directly instead the code.cmd that is in system path.
"%localappdata\Programs\Microsoft VS Code\Code.exe" C:\project1
"%localappdata\Programs\Microsoft VS Code\Code.exe" C:\project2
exit
Good Day.
I have an Powerbuilder application that triggers a batch file to start up a database server.
Below the contents of the batch file:
"C:\Program Files\Sybase\SQL Anywhere 8\win32\dbsrv8.exe" -c 8m -n DEMO "C:\loadcon\db_demo\demo.db"
This all works fine.
However I would like the command window to close automatically after the execution of the batch script. I have spend most of today reading this website and trying options that might work, like adding start, exit, /exit, /c but none work correct. With the start option in front it has a problem with the database switch -c. Repositioning the string quotation marks withing the batch file has undesirable effect on the database startup. However adding /exit at the end - first the the database promts a mssg 'Cant read file /exit' and then the cmd prompt closes - so, something is working but not 100%.
Anybody can enlighten me?
Thanks
Alex
You don't call it with /exit or /c
Batchfile.bat:
"C:\Program Files\Sybase\SQL Anywhere 8\win32\dbsrv8.exe" -c 8m -n DEMO "C:\loadcon\db_demo\demo.db"
EXIT
It has to be a newline
edit
It might be that the program never actually exits, so will never reach the "EXIT" command. Usually when a .bat file is executed with windows scheduler or double-clicked, it will open and close the command prompt as soon as the program finishes and exists.
Might want to consider using vbscript or cscript to execute the command. I can't remember my vbs for batch files so well though :)
REEDIT 16 Apr
Re: your comment, try this?
cd C:\Program Files\Sybase\SQL Anywhere 8\win32
dbsrv8.exe -c 8m -y -q -n DEMO C:\loadcon\db_demo\demo.db
exit
I have three different commands that I want to execute my running one script,
I created a file called as myscript.bat
I want the following two commands to run in sequence when I run the script:
cd C:\Users\johnDoe\Idea\View\Proxy
node proxy.js
PS:And after that I want the cmd to be left open, not close automatically
Leave the bat file as it is, but run it with cmd /k myscript.bat. Also, if there's a chance of the command window opening by default on another drive, you might want to add the line C: to the beginning of the script to change volumes. cd changes folders within a given volume, but it doesn't actually change volumes.
Alternatively, if you just want the window to stay open so you can read the output, but you don't actually want to run any additional commands in it after your commands finish, you can just add the line pause at the end of the script.
#reirab's answer contains the crucial pointer: use cmd /k to create a console window that stays open.
If you don't want to use cmd /k explicitly - say, because you want to open the batch file from Explorer, you have 2 options:
[Suboptimal] Add a cmd /k statement as the last statement to your batch file.
[Better] Write a wrapper batch file that invokes the target batch file with cmd /k.
For instance, if your batch file is startProxy.bat, create another batch file in the same folder, name it startProxyWrapper.bat, and assign the following content:
#cmd /k "%~dp0startProxy.bat"
When you then open startProxyWrapper.bat from Explorer, a persistent console window (one that stays open) will open and execute startProxy.bat.
Currently I want to run a batch file that fires the command git log and show me that log.
After that I need to be able to commit and view the status so this prompt may not disappear after a key press.
I've searched the net and the only answer people have is pause which close the prompt after a keypress.
Does anyone have the solution for me? Currently I made a shortcut to cmd.exe and made the target my folder, but I want to execute some commands also.
Thanks in advance.
This (below) tested OK in Windows 7. To exit the window it creates, type "exit" when done.
start cmd /K "cd \[the-target-folder] && git log"
Where:
[the-target-folder] you replace with your target folder
Note:
&& lets you run two commands on one line
/K is a parameter to the cmd shell program which which carries out the command specified by string and remains.