Batch File

Hi Experts,

I have a batch file say work.bat which contains the following commands:

Command to create CSV file and save in c:\test
Command to create CSV file and save in c:\test
Command to create CSV file and save in c:\test
Command to create CSV file and save in c:\test
Command to create CSV file and save in c:\test

so when I run batch file, it should create 5 csv file. but its creating only 3 or sometimes 4.
The file name are all unique.

to sort it out, I provided break also of 2 min before next command executes but its not helping.


please advice
Dinesh KumarAsked:
Who is Participating?
 
Dinesh KumarAuthor Commented:
I don't know what changes other team members made but when new deployment happened on STAGE, my original batch file( already shared) worked perfectly.
0
 
NVITCommented:
Let us see your code. Attach File.
0
 
Dinesh KumarAuthor Commented:
Commands are correct.. if i run them individually they are working.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Lee SavidgeCommented:
Still need to see the batch file. We can't help otherwise. Running commands at the command line and from in a batch file can have different results.
0
 
Dinesh KumarAuthor Commented:
that i can not put here but yes can  you help in below:

call Command to create CSV file and save in c:\test
call Command to create CSV file and save in c:\test
call Command to create CSV file and save in c:\test
call Command to create CSV file and save in c:\test
call Command to create CSV file and save in c:\test

so If I add call in front of every command, what difference its going to make?
0
 
Lee SavidgeCommented:
If you have a batch file that calls other batch files, when you run the secondary ones, you must prefix the call with CALL so that the process returns back the the caller.

eg:

@echo off
cls
call mybatch1.bat
call mybatch2.bat
echo Done

Open in new window

0
 
Dinesh KumarAuthor Commented:
can we use call with simple command instead of .bat file in case if first command takes too much time in completion.
0
 
Lee SavidgeCommented:
See here for more info on calling functions within a batch file:

http://ss64.com/nt/call.html

and here

http://www.dostips.com/DtTutoFunctions.php#FunctionTutorial.CallingAFunction
0
 
Bill PrewCommented:
Can you at least tell us what in general you mean by:

Command to create CSV file and save in c:\test

Is this a single DOS command?  Is it an execution of a single EXE program?  Or a call to some other script (BAT, CMD, VBS, PS1, ...)?  I appreciate there may be something sensitive that you don't want to post, but perhaps you can share one of the sample lines and obfuscate any sensitive information?

Also, how are you running the script in question?  Is it from Task Scheduler, or just manually somehow?

~bp
0
 
Dinesh KumarAuthor Commented:
I am running it manually by double clicking the batch file which contains  following  7 commands.

D:\apps.exe   --services "S1"   --serviceParameters "E:Year=2011"
D:\apps.exe   --services "S1"  --serviceParameters "E:Year=2012"
D:\apps.exe   --services "S1"  --serviceParameters "E:Year=2013"
D:\apps.exe   --services "S1"   --serviceParameters "E:Year=2014"
D:\apps.exe   --services "S2"   --serviceParameters "E:Year=2014"
D:\apps.exe   --services "S2"
D:\apps.exe   --services "S3"

so here each command will produce a file and place that file on some location so ideally it should give us 7 files, but I am getting 3 or 4 files only and if I run the batch file again, I get all the 7 files on that location. I believe batch command runs in sequence so it would have created 7 files in first run itself.
0
 
Bill PrewCommented:
Thanks.  Perhaps you need to wait for the EXE to finish before running it again, you might try:

start "" /WAIT "D:\apps.exe"   --services "S1"   --serviceParameters "E:Year=2011"
start "" /WAIT "D:\apps.exe"   --services "S1"   --serviceParameters "E:Year=2012"
start "" /WAIT "D:\apps.exe"   --services "S1"   --serviceParameters "E:Year=2013"
start "" /WAIT "D:\apps.exe"   --services "S1"   --serviceParameters "E:Year=2014"
start "" /WAIT "D:\apps.exe"   --services "S2"   --serviceParameters "E:Year=2014"
start "" /WAIT "D:\apps.exe"   --services "S2"
start "" /WAIT "D:\apps.exe"   --services "S3"

Open in new window

~bp
0
 
Dinesh KumarAuthor Commented:
why start because it's exe?
0
 
Dinesh KumarAuthor Commented:
it's not working
0
 
Bill PrewCommented:
The START command will kick off an executable, and has a number of options that can be used to fine tune the launch of the executable.  In this case we are interested in the /WAIT option, which means don't continue on to the next statement in the BAT script until the EXE ends execution.

Without the START /WAIT, some EXEs may turn control back over to the BAT script as soon as they start running, rather than when they end.  In that case since you are running the same EXE several times there could be a chance that they interfere with each other.  So to test that out I wanted to try the START /WAIT approach to see if only having one running at a time helped with your problem.

~bp
0
 
Bill PrewCommented:
"it's not working "
Does that mean some CSV files were produced and some were not, or does it man the EXE never ran at all, or you got some errors, etc?

~bp
0
 
Dinesh KumarAuthor Commented:
I am getting some of mine errors also.. so  will update once I fix them.

thanks for providing start/wait command.
0
 
Dinesh KumarAuthor Commented:
one question
Does start/wait is not the default behavior?
0
 
Bill PrewCommented:
No, /WAIT is not the default for START command.  For a sample example of this, try the following two commands from a command prompt.

start notepad.exe

Notice that the command prompt gets control as soon as notepad starts.  Close Notepad.

start /wait notepad.exe


Notice the command prompt doesn't get control back until you close notepad.

~bp
0
 
Dinesh KumarAuthor Commented:
there was no change in the batch file so no modification required.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.