Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File

Posted on 2016-08-04
19
Medium Priority
?
60 Views
Last Modified: 2016-08-16
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
0
Comment
Question by:Dinesh Kumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 3
  • +1
19 Comments
 
LVL 25

Expert Comment

by:NVIT
ID: 41743749
Let us see your code. Attach File.
0
 

Author Comment

by:Dinesh Kumar
ID: 41743781
Commands are correct.. if i run them individually they are working.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41743784
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dinesh Kumar
ID: 41743803
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
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41743976
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
 

Author Comment

by:Dinesh Kumar
ID: 41743982
can we use call with simple command instead of .bat file in case if first command takes too much time in completion.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41743990
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
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41744124
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
 

Author Comment

by:Dinesh Kumar
ID: 41744134
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
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41744154
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
 

Author Comment

by:Dinesh Kumar
ID: 41744264
why start because it's exe?
0
 

Author Comment

by:Dinesh Kumar
ID: 41744303
it's not working
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41744305
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
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41744308
"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
 

Author Comment

by:Dinesh Kumar
ID: 41744369
I am getting some of mine errors also.. so  will update once I fix them.

thanks for providing start/wait command.
0
 

Author Comment

by:Dinesh Kumar
ID: 41748254
one question
Does start/wait is not the default behavior?
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41748578
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
 

Accepted Solution

by:
Dinesh Kumar earned 0 total points
ID: 41753435
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
 

Author Closing Comment

by:Dinesh Kumar
ID: 41757609
there was no change in the batch file so no modification required.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question