Closing cmd window after opening it with shellExecute() - batch-file

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

Related

Exit CMD after batch file executes

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)

Jenkins job stuck after command start

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.

Batch File Ending Prematurely

I have a batch file with the following commands (to set up a compiler):
del Yylex.java
jflex scanner.flex
del parser.java
java -jar java-cup-11a.jar parser.cup
However, for some reason, after the conclusion of jflex scanner.flex, the batch script ends and command prompt closes. If I just run that command separately, this does not happen. Does anyone know what's wrong?
Is jflex a batch file?
If so, try
CALL jflex ...
or
start /wait "" jflex ...
(well, actually - give it a whirl anyway, can't hurt...)
When bat is asked to run another batch, it merely transfers control to that other batch and has no idea of where to return. CALL or START gives it a ticket home...

Prevent batch file in CMD from closing without using Pause

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.

Cmd window to close after opening process with .bat

I'm new with batch file and the code I'm using I had to find but it always opens cmd but doesn't close it after the program is open. I'm aware that it doesn't close because it's a window process and cmd doesn't close until after the window is closed. I would like to to close after it opens the window. Here is the code:
"C:\Program Files\Java\jre7\bin\javaw.exe" -Xmx1G -Xms1G -jar "Minecraft_Server.exe"
I've used many different ways close it like putting Exit at the end or putting cmd /c in front but that didn't work.
Update
The start command does not seem to work with multiple parameters.
Only solution I could come up with is creating a windowless executable that handles the executing with multiple parameters.
Original answer
I've tested the following and it works because Progra~1 is the a conversion of the Program files folder in oldskool 8 character style:
start c:\Progra~1\Intern~1\iexplore.exe -new -k "http://www.google.com/"
I cannot verify this because I do not have java, but it should work:
start C:\Program~1\Java\jre7\bin\javaw.exe -Xmx1G -Xms1G -jar "Minecraft_Server.exe"
However if more folders start with Progra then it could also be Progra~2, Progra~3 etc. You would have to try what works.

Resources