Creating a .bat file - batch-file

I am trying to execute a command CSRUN.exe with certain parameters from command prompt. I am able to do this using command prompt. Everytime instead of invoking this from the command prompt, i thought of writing a batch file, where in a single click will help me and also i forward this to someone who wants to execute.
Following is the one i am executing from the command prompt, which i want to have in a batch file
C:\Program Files\Windows Azure SDK\v1.1\bin>csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
Can somebody suggest me how to create a batch file for invoking this command?

Just put those commands in a file
csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
and name it something.bat

Just copy
csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
inside an empty file and save it as a .bat..

Try using the start command and, if csrun.exe is not in your path you will need to specify an exact path for it:
start csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
Save the above in a .bat file.
Also remember to put double quotes around paths with spaces in them.

Related

How to start Python virtual environment in .bat batch file?

I need to set up a long list of temporary environment variables every time when I start a Python Flask app on Windows 10. Now I would like to create a batch file to run with all settings in one double click. The following lines run well if I copy them and paste to cmd prompt, but I couldn't run them in the batch file.
The execution of batch file always gets tripped and exited at the 2nd line venv\scripts\activate in the batch file, which has no issue at all if I copy and paste line by line at cmd.
cd C:\py\project
venv\scripts\activate
set env1=val1
set env2=val2
set FLASK_APP=some.py
flask run
One of the many (far too many) quirks of .bat files is that if you launch another .bat file, it doesn't know where to return to.
You need to explicitly call it:
call venv\scripts\activate
you can just use
start venv\Scripts\activate
This will open up a new terminal just like that... you can pass other commands using the && or & sign.

Why can't I use the command prompt after running a batch file on it?

So I have a batch file that simply runs an exe file. I want to be able to open the command prompt, run the batch file, then... I want to type another command in the command prompt.
here is the code that is in the batch file called "sublime.bat":
"C:\Sublime Text 3\sublime_text.exe"
I open cmd in the directory with my bat file and I type:
"sublime.bat"
It works by opening sublime text but the cmd cursor starts flashing and I can no longer type anything until I close sublime text.
I want to be able to open sublime text and type commands out while still having sublime text open. Please help, thanks.
Command prompt doesn't execute a further line, while a command is on execution. It executes commands serially, not parallelly. So if you want a command to be executed cmd should return from executing previous one.
Here, in "sublime.bat" you have called a batch file which contains a command of executing another program. So, cmd waits for the result of executing the bat file and thus stuck there.
You can use start "/k" "C:\Sublime Text 3\sublime_text.exe" in your "sublime.bat". This holds only the start command and cmd gets free after starting the file.

can we use multiple "cd" commands in a batch file?

I was not able to add multiple change directory commands in a single batch file:
cd C:\abc\def
do something
cd C:\def\ghi
do something
It stops in the second line, and does not come back to execute the third line.
Yes you can.
I am betting that what you're doing in step 2 is calling another batch file, without using the call keyword.

Execute .exe from a batch file

In an application folder, there are n number of files. The application exe name "ClearMongoDb.exe" take some parameter like dbname.
ex: clearMongoDb.exe -db "SynchoMeshDB"
I am stuck with below :
I want to execute the exe from a batch file with same parameters
the batch file will be placed in the same application folder.
user can copy the application folder to any location
If user double clicks on the .bat file the exe should start working.
User should not be required to make any changes in .bat file
If the batch file is in the same folder as the executable, then you can do like this:
clearMongoDb.exe -db "SynchoMeshDB"
Just add this line in your batch file. Now the refference is in the same folder as the executable, no matter where the ENTIRE folder is moved (or at least the executable and batch file).
update:
As foxidrive mentioned, in order to see the output, place a PAUSE command at the end. So, your batch file should be like this:
clearMongoDb.exe -db "SynchoMeshDB"
PAUSE
If you just want to pass all the parameters given to a batch file to an EXE called from that batch file, use %*.
foo.exe %*
How do I pass command line parameters to a batch file?
You can just use a shortcut to the file and add the parameters on the path. no need for an extra batch file.
edit: unless you want to pass the batch file parameters to the .exe, as some people read this. what do you want to do? execute a .exe with the same parameters each time, or pass the .bat parameters to the .exe?

Force bat file to use non default cmd.exe

I'm writing a .bat file to handle some script generation automatically so I don't have to type in half a dozen command arguments each time I want to run it.
I have to run a vb script from the batch file
#call ..\Database\scripts\runscriptupdates.vbs
However the script will only run if using the the command prompt from
C:\Windows\SysWOW64\cmd.exe
By default the bat file uses the cmd.exe in system32
C:\Windows\System32\cmd.exe
Is there a way to force the batch file to use this cmd.exe to run the vbs file? I've been trawling the web for about an hour now and haven't found anything which helps (so far).
I've tried running the syswow64 with "start ..." however it doesn't seem to take the arguments after it.
Many thanks, Neil
You can try:
%windir%\SysWoW64\cmd.exe /c mybatch.bat
This will run the batch itself from a 32-bit command prompt. Thus, the call to your vbs will also be coming from a 32-bit command prompt.
I also had this problem, and I found the way to solve it.
You just need to change System Variables.
Go to Control Panel » System » Advanced System Settings » Environment Variables.
Find the variable ComSpec, then just click Edit... and change the path to "C:\Windows\SysWow64\cmd.exe"
Try typing this one line in your batch file.
%windir%\SysWoW64\cmd.exe /c ["]cscript [script name] [host options] [script arguments]["]
Where:
script name is the name of the script file, including the file name extension and any necessary path information.
host options are the command-line switches that enable or disable various Windows Script Host features. Host options are always preceded by two slashes (//).
script arguments are the command-line switches that are passed to the script. Script arguments are always preceded by one slash (/).
Example:
%windir%\SysWoW64\cmd.exe /c "cscript VoltageDrop.vbs /"Campbell.sin" "L08""
Note: In this line I do not pass any host options. This command will execute the string,
cscript VoltageDrop.vbs /"Campbell.sin" "L08"
as a command in the 32-bit command prompt.

Resources