Open application with hidden cmd.exe - batch-file

To open an Android Virtual Device, I was recommended to add a shortcut or a batch file with the next line:
C:\android-sdk\tools\emulator.exe -avd MyAVD
Nevertheless, when I do so, this opens with a command line window, which if I close by error (Something frequently since I work with many command line windows for debugging the apps), It also closes the AVD emulator.
I want to open the AVD without the command line window, to prevent this, I was recommended to do so with cmd /c or with start at the beginning, but it isn't working either. Anyone can tell me how should I do this?

You can use a VBScript to open the command prompt window hidden
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\batchfile.bat"), 0, True
If you save that as .vbs and make sure to replace C:\batchfile.bat with the location of yours, this will run the command hidden.

This should do it, it should run as a subprocess of taskeng.exe in Task Manager.
schtasks -create -tn foo -tr <command> -sc once -st 00:00 -ru system
schtasks -run -tn foo
schtasks -delete -tn foo -f
ref

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.

How to keep typing in cmd after opening emacs with bat file

I have a bat file emacs.bat as shown:
#echo off
"C:\emacs-24.3\bin\emacs.exe" -q -l w:\handmade\misc\.emacs
After I run emacs.bat emacs opens, no problems. However cmd does not let me continue typing commands while emacs is open. I would like to be able to type commands into cmd with emacs open.
How can I achieve this?
The solution is to add start "emacs" to the beginning of the command in emacs.bat:
start "emacs" "C:\emacs-24.3\bin\emacs.exe" -q -l w:\handmade\misc\.emacs
"emacs" is required for the text for the CMD title bar.
You can also make it work without opening a new window by adding /B after "emacs".

Closing cmd window after opening it with shellExecute()

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

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.

Resources