running batch files inside another batch file - windows

I have made a batch script to run some .exe files and .bat files. The format of the script is as follows:
a.exe
b.exe
c.bat
d.bat
e.bat
f.exe
g.exe
but the problem is when I run the script it is only executed till c.bat. d.bat is not executing. Is there any problem in writing the batch script for executing other batch files?

just in case you missed the full application of call
a.exe
b.exe
call c.bat
call d.bat
call e.bat
f.exe
g.exe
is how your script should now look.

if you use the 'call' command, the batch files next batch/exe file wouldn't execute unless the batch file stops. Instead, use the 'start' command. that way, it'll execute the batch in a new window

Related

nircmd: I can't run another batch file with nircmd.exe?

I have wrote a batch file that i want to run another program with nircmd.exe. But the problem is i can't run it? The batch file(Matrix.bat) runs correctlyby double-click it. But when i trying to open it with nircmd.exe, it doesn't run? why?
i tried two method:
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
start %INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
%INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
The exec command in nircmd does not run batch files but executable files. Change your code to
start "" "%INSTALLPATH%\nircmd.exe" exec show "%comspec%" "%INSTALLPATH%\Matrix.bat"
Now, nircmd executes a cmd instance that will handle the batch file execution
The problem was in path of nircmd.exe. I set path of nircmd but i didn't know why it isn't work correctly? with "pushd" command i set the path of cmd into where nircmd.exe exist. and Bow!!! everything works cerrectly. Maybe a syntax problem. If everyone know that say it here.
SET INSTALLPATH=d:\atlantic
pushd %INSTALLPATH%
nircmd exec show Matrix.bat

How can I test for errors in a .bat file that calls an .exe?

I'm writing a .bat file that calls a .exe that processes a bunch of documents. I am writing it to test the .exe's performance. Currently, the .bat file runs a for loop to run the .exe on every file in the folder. Sometimes the .exe will run into errors and will not be able to finish running due to incompatibility between the document and the .exe (still working on perfecting the .exe). How can I tell my .bat file to mark the bad files as errors and continue processing the rest of the files?
Edit: I don't want to terminate the batch file; I'd like to terminate the .exe for that specific file, and then continue with the for loop.

prevent Windows .bat file from quiting

I have a very simple Windows .BAT file:
set PATH=c:\xxx;%PATH%
call foo.pl
set VAR=true
I thought "call" will start a new batch process, without affecting the current one. However, the batch file exited immediately after the foo.pl finished executing. The set VAR=true has never been called.
Is there a way to fix it?
foo.pl is not a batch file, it is a Perl script.
So you need to use
path c:\xxx;%PATH%
"Path to\Folder With\perl.exe" "foo.pl"
rem Additional batch code executed after Perl script execution finished.
In other words you have to run the console application perl.exe best with full path, or with just perl.exe if program files folder of Perl is not the same on all computers on which this batch file is used and hopefully PATH contains also the directory containing perl.exe.
If you specify on a command line or in a batch file just foo.pl, Windows looks in Windows registry which application is associated with .pl for action Open. If there is such a file association, Windows runs this application in a separate process like when using command start.
So using call foo.pl is like using start foo.pl.
PATH is not only an environment variable, but also an interal command written for changing the value of environment variable PATH at any time within a batch file. This is the reason why I removed set from first line. It is better to use internal command path for modifying environment variable PATH.

How to run the batch file commands sequential?

I am trying to call the 2 batch files in another batch file.But the batch files are running parallel. I want to run those batch files one after another.
Please provide the solution if any?
call batch1.cmd
call batch2.cmd
There you go.

windows 7, cannot invoke exe from bat file

In windows 7 a bat file was made:
rem set UD_LOG_FILE_PATH=%temp%\defrag_native.log
C:
cd \Windows\System32
udefrag.exe --optimize-mft C:
udefrag.exe -o C:
pause
I can double click the bat file and it runs OK. However, the bat file was made to be invoked from a running program. When the program shells out to the bat file the following error is produced:
'C:\Windows\System32\udefrag.exe' is not recognized as an internal or external command,
operable program or batch file.
Invocation is done using Shell in VB6. Different things were tried. First the bat file was called directly, then with C:\Windows\System32\cmd.exe /c, then with C:\Windows\SysWOW64\cmd.exe /c. All produce the same result. The bat file runs but will not run the exe file within the bat file. But the bat file works OK if run directly. Please help. Thanks
Google says that udefrag.exe is a third party program. If it is in c:\windows\system32 then it is on the path and you only need the last 3 lines in your batch file. Try this first and see if it needs elevated permissions. If you have UAC turned off then turn it back on for the test. Your VB program may not have the right permissions.
#echo off
udefrag.exe --optimize-mft C:
udefrag.exe -o C:
pause
I used task scheduler to resolve this. A task was created with no trigger named "defragment". The task invokes the bat file. Instead of invoking the bat file from the running program the following command is given:
schtasks /Run /TN defragment
This runs the bat file through the task scheduler. I don't know why I have to do it that way, but it works good.

Resources