Note: This question is similar to a question I asked 4 months ago, but not the same issue.
I have the following batch script:
@echo off
set DIR=U:\sendToJeff
echo Starting list filter...
%DIR%\OFCNSFilter.exe %DIR%\filter.ini %DIR%\OFCNS_FINAL_mod.xml %DIR%\outfile.xml
echo errorlevel = %errorlevel%
When run in cmd, i get the following output:
U:\sendToJeff>testscript.bat
Starting list filter...
U:\sendToJeff>
OFCNSFilter.exe is a .NET 3.5 program (written in C#) running on Windows Server 2003 R2 Standard x64 Edition SP2. Notice that the second ECHO
command is not executed. However, if I ECHO the %ERRORLEVEL%, it is 0 (0=success, 1=failure). It's also apparent that the program actually runs because outfile.xml is created.
Here's where I get even more confused. If I run it once, I get the above output. However, if I try to run it more than once in the same cmd window, I get the following output:
U:\sendToJeff>testscript.bat
Starting list filter...
U:\sendToJeff>testscript.bat
U:\sendToJeff>
Has anyone ever seen this kind of behavior in a batch script before? I would appreciate any insight on how to fix this. If it helps, I also utilize the System.Xml.Linq library.
I finally figured it out. In a past iteration of the program, I was outputting data to the console. This data was UTF8 encoded so I had to do Console.OutputEncoding = System.Text.Encoding.UTF8;
in order to get the data to print correctly. While this worked on my machine and on the server running Windows Server 2012 R2, I guess there is an issue doing that on Windows Server 2003. Simply removing that line of code fixed everything. So, this ended up being more of a C#/VB.NET question than batch scripting, but I hope someone may find this useful.