Solved

Batch File

Posted on 2016-08-04
19
45 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 24

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 53

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 53

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 53

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 53

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 53

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the web config for a running service on Windows 10 16 42
sleep laptop 20 59
Robycopy Copy Data \ Disk to Disk (new\changed data) 18 82
facebook change 4 37
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

810 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