all the commands are not getting executed in bat file? - batch-file

after the startup.bat command I wanted to start chrome with url: http://localhost:8080/Nexus but bat file getting stopped after tomcat is being started up.
Code in the batch file is as follows:
#echo off
start cmd
cd I:\Users\5251966\Nexus
echo yes|copy catalina.bat I:\apache-tomcat-7.0.55-windows-x64\apache-tomcat-7.0.55\bin
echo yes|copy tomcat-users.xml I:\apache-tomcat-7.0.55-windows-x64\apache-tomcat-7.0.55\conf
cd I:\apache-tomcat-7.0.55-windows-x64\apache-tomcat-7.0.55\bin
startup.bat
start chrome http://localhost:8080/Nexus

Here's some example code for you:
#Echo Off
Set "srcDir=I:\Users\5251966\Nexus"
Set "dstDir=I:\apache-tomcat-7.0.55-windows-x64\apache-tomcat-7.0.55"
Copy /Y "%srcDir%\catalina.bat" "%dstDir%\bin"
Copy /Y "%srcDir%\tomcat-users.xml" "%dstDir%\conf"
CD /D "%dstDir%\bin"
Call "startup.bat"
Start chrome http://localhost:8080/Nexus

Use call to call other batch files from a batch file, otherwise your parent batch file terminates and won't run any more commands after invoking the child:
call startup.bat

Related

How to run .EXE from .BAT inside the folder where .EXE is locating

To recreate my problem you need to understand that I have next files in 2 folders.
K:\Script.bat
K:\Project\PortChanger.exe
K:\Project\settings.xml
I want to launch PortChanger.exe using Script.bat that contains next line:
start "K:\Project\PortChanger.exe"
This script is actually executing Program.exe, but my program throws me exception since PortChanger.exe can't find Settings.xml.
How can I launch PortChanger.exe from "K:\Project\", not from "K:\"? Now it seems like .BAT taking .EXE code and just running it where .BAT is locating.
To make it even more clear:
You could use Start with its /D option:
Start "" /D "K:\Project" "K:\Project\PortChanger.exe"
Open a Command Prompt window and enter start /? to read its usage information.
I would suggest you rather use pushd and popd
#echo off
pushd "K:\Project"
start "" PortChanger.exe
popd
pushd will change to the directory, launch the executable from it, then popd will return to the previous directory stored.

CMD/FTP to create folder using to today date & connect ftp download into created folder

I'm new to this cmd/FTP command. I would like to create a new folder at my local directory using today's date and connect to FTP to download the specific file to the newly created folder. If I manually type in command one by one at cmd, it has no issue. But when I use a batch file to run, my command stopped at FTP.
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4"_"job%
mkdir C:\%name%
cd C:\%name%
ftp
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget -i *.*
I did try to separate my command to two batches;
1. folder creation
2. FTP download but the file downloaded didn't go into the folder I created. the downloaded file went to C:\Document & Settings.
main batch file
#echo off
call rename.bat
ftp -i -s:ftp.txt
rename.bat
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd c:\%name%
ftp.txt
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget *.*
close
Another method I try is using '!' when in FTP environment, then create a folder then exit back to FTP environment. This method again doesn't work with the batch file. Please help
It seems that with command extensions enabled, the working directory set by a child batch file is lost, then the batch file exits.
I'm not sure how to solve it, but you actually do not need the rename.bat file to be a separate file. This "main batch file" should work:
#echo off
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd /d c:\%name%
ftp -i "-s:%~dp0\ftp.txt"
Also note the /d added to cd. Without that your batch will not work when started from another drive. You also have to use %~dp0 to refer to the batch file folder for the ftp.txt. As at the time ftp is called, you have changed to the target directory.
You possibly do not even need the command extensions to be enabled. So simply removing the setlocal enableextensions might solve the problem too. Though you still need the %~dp0 and /d.
I've decided to post this, although similar to the answer given, there are a couple of differences.
It creates the text file, then deletes it, (this keeps everything more portable).
I have corrected your directory name, (because of a typo).
#Echo Off
Set "Name=%DATE%"
Set "Name=%Name:~-10,2%-%Name:~-7,2%-%Name:~-4%_job"
MD "C:\%Name%" 2>Nul
CD /D "C:\%Name%" || Exit /B
( Echo open 192.168.31.93
Echo *user*
Echo *password*
Echo binary
Echo cd *directory*
Echo mget *.*
Echo close
)>"ftp.txt"
FTP -i -s:ftp.txt
Del "ftp.txt" 2>Nul
Exit /B

Command only works in cmd line but not in batch file

I want to copy some file. It can already be copied by using the command line, but not in a batch file.
#echo off
E:
cd Testing\ihelpdesk_extraction
XCOPY Testing.csv "\\10.44.103.111\Shared_Folder\Shared_Folder\"
exit
My current directory is C:\Users\Administrator.
Use full paths:
i.e.:
XCOPY "E:\Testing\ihelpdesk_extraction\Testing.csv" "\\10.44.103.111\Shared_Folder\Shared_Folder\Testing.csv"

How to run any program with batch file from any specific location

I wrote a batch file for open a specific program but it is not working.I wrote this :
#echo off
C:\Windows\System32\cmd.exe /K "cd /d C:\Program Files (x86)\HTC\HTC Sync Manager\"
start HTCSyncManager.exe
When I run the batch file only this window come, program do not start. How to fix this
#echo off
For /r c: %%f in (path goes here /HTCsyncmanager.exe) do (
start "%%f"
"%%f"
)
Remove the invoking of cmd.exe. All that's doing is starting a new instance of the command processor, which is not what you need at all. (You probably don't need the start, either.)
#echo off
cd /d "C:\Program Files (x86)\HTC\HTC Sync Manager\"
HTCSyncManager.exe
#echo off
start "HTCSyncManager" "C:\Program Files\(x86)\HTC\HTC Sync Manager\HTCSyncManager.exe"
This will open HTCSyncManager.

How do I execute cmd commands through a batch file?

I want to write a batch file that will do following things in given order:
Open cmd
Run cmd command cd c:\Program files\IIS Express
Run cmd command iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx
Note: The cmd window should not be closed after executing the commands.
I tried start cmd.exe /k "cd\ & cd ProgramFiles\IIS Express", but it is not solving my purpose.
So, make an actual batch file: open up notepad, type the commands you want to run, and save as a .bat file. Then double click the .bat file to run it.
Try something like this for a start:
c:\
cd c:\Program files\IIS Express
start iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
start http://localhost:8088/default.aspx
pause
I think the correct syntax is:
cmd /k "cd c:\<folder name>"
This fixes some issues with Blorgbeard's answer (but is untested):
#echo off
cd /d "c:\Program files\IIS Express"
start "" iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
timeout 10
start http://localhost:8088/default.aspx
pause
cmd /c "command" syntax works well. Also, if you want to include an executable that contains a space in the path, you will need two sets of quotes.
cmd /c ""path to executable""
and if your executable needs a file input with a space in the path a another set
cmd /c ""path to executable" -f "path to file""
#echo off
title Command Executer
color 1b
echo Command Executer by: YourNameHere
echo #################################
: execute
echo Please Type A Command Here:
set /p cmd=Command:
%cmd%
goto execute
start cmd /k "your cmd command1"
start cmd /k "your cmd command2"
It works in Windows server2012 while I use these command in one batch file.
cmd /k cd c:\
is the right answer
I was trying to run a couple of batch files parallely at startup, if a condition was true.
For this I made a parent batch file which should have checked for the condition and invoke the other child batch files if the condition was true.
I tried to achieve it via START but it gave me an empty black command prompt running in the directory of children batch files, instead of running the children batch files themselves
The thing which worked for me was by using a combination of START and CALL
As an example
condition ...
start call "C:\Users\Amd\conn\wsl_setup - conn1.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn2.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn3.bat"
I know DOS and cmd prompt DOES NOT LIKE spaces in folder names. Your code starts with
cd c:\Program files\IIS Express
and it's trying to go to c:\Program in stead of C:\"Program Files"
Change the folder name and *.exe name. Hope this helps

Resources