can we use multiple "cd" commands in a batch file? - 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.

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.

Cannot run batch file with xcopy command

The code in batch file is :XCOPY "D:\hosts" "C:\Windows\System32\Drivers\etc" /R /Y. But it doesn't work. cmd run like :
How do I fix this?
Based on the output, I'd say you've called your batch file xcopy.cmd or `xcopy.bat.
That means, when it tries to call the actual xcopy executable, it instead calls itself in an infinitely recursive loop.
If that is the case, you have a couple of options:
Rename your batch file to something more sensible, such as copy_hosts.cmd, something that's not likely to clash with a real command; or
Make sure you call xcopy.exe explicitly from your batch file, so it goes and gets the real one.

running multiple exe through batch file

Experts, I am trying to run a bat file using the below.
start /wait "D:|Silent_installer.bat"
start /wait 'D:def.bat"
It's happening like both bat files running at the same time.
But I wanted the first bat file to run completely then def.bat should start. The first bat file takes approx 60 min and inbetween second bat file starting.Ideally I wanted the first batch to complete 100% then second bat file should start.
I also used call like below but no luck
call "abc.bat"
call "def.bat"
Any suggestions would be of great help
You have to use start "" /wait command with the program in the abc.bat file itself. One of the programs being used inside abc.bat is multi-threaded and lets the batch file end before it finishes.
why not simply
"abc.bat"
"def.bat"
in your batch file ?
You could use Start command to start application
Ok. Two points here.
The start command is used for asynchronous execution, so if you " wanted the first batch to complete 100% then second bat file should start", just don't use it!
In order to execute two Batch files from inside another one, you must use call command as you show us in your question, that is:
.
call "abc.bat"
call "def.bat"
Perhaps if you explain what "I also used call like below but no luck" means, we may help you in a better way.
PS - Did you realized that your first example
"D:|Silent_installer.bat"
contain an invalid character | in the name of the Batch file?

Batch script stops after first call to other batch script

I'm attempting to execute a batch script that currently looks like this:
D:
cd D:My Documents\FtpSolution\Test
getftp.bat
call delimconvert.exe
call convert-to-xls.bat
However this stops dead after getftp.bat has run.
What am I doing wrong? It's important that these commands all run sequentially.
Use call:
Calls one batch program from another.
CALL [drive:][path]filename [batch-parameters]
batch-parameters Specifies any command-line information required by the
batch program.
If you invoke other batch files without call then control is passed to them but not back again (which is what call changes).
use start command to launch it in a new window.
start /wait getftp.bat
Try using "Goto :EOF" rather than "exit" at the end of the batch file that you're calling - in your case, the getftp.bat file...
That's what fixed mine - tested on Win10 enterprise.

Creating a .bat 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.

Resources