Call vs Start: Reasons why your batch script might not be writing output to file
If you are calling another batch script from your source script you need to call it by preceding keywords
But here also there is a catch:
Start will open a new cmd window and execute command there and will not write the output in external text file if you have redirected it there:
For example if you execute BatchScriptSource.bat it will not write anything in SomeTextFile.txt although it will be created.
Contents of BatchScriptSource.bat
On the other hand Call will execute BatchScript.bat in the scope of same cmd session/window where BatchScriptSource.bat is being executed and will execute commands sequentially and write the output in SomeTextFile.txt as expected.
Contents of BatchScriptSource.bat
Call
or Start
before the script name.But here also there is a catch:
Start will open a new cmd window and execute command there and will not write the output in external text file if you have redirected it there:
For example if you execute BatchScriptSource.bat it will not write anything in SomeTextFile.txt although it will be created.
Contents of BatchScriptSource.bat
start BatchScript.bat >> SomeTextFile.txtContents of BatchScript.bat
tasklistOutput Using Start:
On the other hand Call will execute BatchScript.bat in the scope of same cmd session/window where BatchScriptSource.bat is being executed and will execute commands sequentially and write the output in SomeTextFile.txt as expected.
Contents of BatchScriptSource.bat
call BatchScript.bat >> SomeTextFile.txtContents of BatchScript.bat
tasklistOutput Using Call:
Comments
Post a Comment
Note:Please be gentle while commenting and avoid spamming as comment are anyways moderated thank you.