Solved

Batch File

Posted on 2016-08-04
19
39 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
  • 10
  • 5
  • 3
  • +1
19 Comments
 
LVL 23

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
 

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 51

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 51

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 51

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 51

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 51

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now