Reputation: 387
I am very new to windows batch scripting, this can be a silly question. I am running following batch file: "traffic.bat"
start /B netperf.exe -H HOST IP >> file.txt
start /B netperf.exe -H HOST IP >> file.txt
start /B netperf.exe -H HOST IP >> file.txt
...
The first command is working properly but for further commands, i am getting following error: "The process can not access the file because it is being used by another process"
I know on linux this works fine: "traffic.sh"
netperf.exe -H HOST IP >> file.txt &
netperf.exe -H HOST IP >> file.txt &
netperf.exe -H HOST IP >> file.txt &
I want to achieve very similar to the "traffic.sh".
Upvotes: 1
Views: 1523
Reputation: 4039
Did you try cygwin? I think that your "traffic.sh" script might work with some minor changes (perhaps interpreter and line endings)
Upvotes: 0
Reputation: 3900
Here is another way to redirect the output of multiple commands into the same file all at once:
...
(
start /B netperf.exe -H HOST IP
start /B netperf.exe -H HOST IP
start /B netperf.exe -H HOST IP
::Add more commands if needed
)>>file.txt
Unfortunately, I have no way to test if this will work in your current situation.
Upvotes: 0
Reputation: 6620
The reason its doing so is that all the processes are trying to use the file at once. You need to wait for each one to complete its task. All you have to do is include /wait
parameter for te start
command. Try this:
start /wait /B netperf.exe -H HOST IP >> file.txt
start /wait /B netperf.exe -H HOST IP >> file.txt
start /wait /B netperf.exe -H HOST IP >> file.txt
...
And that should work fine!
Mona
Upvotes: 3