Note that there are some explanatory texts on larger screens.

plurals
  1. POconsole.writeline >> redirectedoutput.txt garbled
    text
    copied!<p>I have a VB.NET 3.5 sp1 console application running on Windows XP sp3 from a batch file:</p> <pre><code>"D:\Program Files\PartsDepotJob\PartsDepotJob.exe" &gt;&gt; "D:\Program Files\PartsDepotJob\partdepot.log.txt" </code></pre> <p>The output looks like the following:</p> <blockquote> <p>2/10/2009 9:03:19 AM<br> Processing PO#: 2100 in 002<br> Created OE# 135<br> Processing PO#: 2100 in 003<br> Created OE# 136<br> DONE<br> 2/10/2009 9:03:30 AM<br> Processing PO#: 2100 in 002<br> Created OE# 137<br> Processing PO#: 2100 in 003<br> Created OE# 138<br> DONE</p> </blockquote> <p>However when I run the same thing at my client on their Windows 2003 sp2 (also w/ .NET 3.5 sp1) box the output gets garbled as follows:</p> <blockquote> <p>2/9/2009 4:03:37 PM<br> DONE<br> 2/9/2009 4:04:06 PM<br> DONE<br> 2/9/2009 4:11:01 PM<br> DONE<br> 2/9/2009 4:30:23 PM<br> Processing PO#: 1649400 in 702<br> Created OE#<br> 1/1/1900 4:30:26 PMCreated OE# 49<br> 1/1/1900 4:30:26 PMProcessing PO#: 1649500 in 702<br> Created OE# 49<br> 1/1/1900 4:30:28 PMCreated OE# 50<br> 1/1/1900 4:30:28 PMDONE </p> </blockquote> <p>ie., sometimes CrLf are removed and the output sometimes seems to be prefixed with 1/1/1900 {time}.</p> <p>Any idea's as to what could cause this? </p> <p>The relevent code is a follows:</p> <pre><code>Imports Wisys.AllSystem Imports Wisys.Oe Imports Wisys.Po Imports System.Configuration Imports System.Data Imports System.Linq Public Class clsPartsDepot Private wsConn As Wisys.AllSystem.ConnectionInfo = Nothing Private wsPartDepotSalesOrd As Wisys.Oe.OrderEntryTables = Nothing Public Function ProcessPartDepotOrders() As Boolean Dim errMsg As String = "" Try Console.WriteLine(Now().ToString) ''//sendBadPOLineEmailtoDepot("test") Dim dsPO As New Data.DataSet Dim dbName As String = "" Dim dbServer As String Dim partDepotDbName As String = ConfigurationManager.AppSettings("partDepotDbName") Dim partDepotDbServer As String = ConfigurationManager.AppSettings("partdepotDBserver") Dim KeyName As String = "" Dim billToCompany As String ''//, billtoCompAddr1 As String Dim dtBillTo As DataTable Dim i As Integer = 1 Dim appkeyQry = From key In ConfigurationManager.AppSettings Where key Like "CompanyDbName*" Select key ''//for each company database look for PO's For Each KeyName In appkeyQry dbName = ConfigurationManager.AppSettings(KeyName) dbServer = ConfigurationManager.AppSettings("CompanyDbServer" &amp; i) billToCompany = ConfigurationManager.AppSettings(dbName) dtBillTo = GetCustomer(billToCompany, partDepotDbName, partDepotDbServer) If dtBillTo.Rows.Count = 0 Then Throw New Exception("Customer record for company database '" &amp; dbName &amp; "' not found in the parts depot!") End If ''//billtoCompAddr1 = dtBillTo.Rows(0)("cmp_fadd1") ''//get all the unprocessed, printed PO's from the current company. dsPO = GetPoDataset(dbName, dbServer) If IsNothing(dsPO) Then Console.WriteLine("Error processing part depot: " &amp; errMsg) Exit Function End If Dim itemNum As String, qtyOrd As Double, requestDate As Date, promiseDate As Date, lineNum As String, itemPrice As Double Dim errNum As Integer = 0 Dim poNum As String = "" ''//for each unprocessed, printed PO in the current company For Each dr As DataRow In dsPO.Tables(0).Rows If poNum &lt;&gt; dr("ord_no") Then Console.WriteLine("Processing PO#: " &amp; dr("ord_no") &amp; " in " &amp; dbName) If Not poNum = "" Then 'for first run don't close it, not open wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg) wsConn.Dispose() wsConn = Nothing End If wsConn = New Wisys.AllSystem.ConnectionInfo OpenWiSysConn(partDepotDbName, partDepotDbServer, True) If Not poNum = "" Then 'for first run don't Dispose it; already equal to nothing If Not IsNothing(wsPartDepotSalesOrd) Then wsPartDepotSalesOrd.Dispose() wsPartDepotSalesOrd = Nothing End If wsPartDepotSalesOrd = New Wisys.Oe.OrderEntryTables wsPartDepotSalesOrd.Connection(wsConn, errMsg) With wsPartDepotSalesOrd.OrderHeader .UserName = My.User.Name .Ship_to_name = If(IsDBNull(dr("cmp_name")), "", dr("cmp_name")) .Ship_to_addr_1 = If(IsDBNull(dr("cmp_fadd1")), "", dr("cmp_fadd1")) .Ship_to_addr_2 = If(IsDBNull(dr("cmp_fadd2")), "", dr("cmp_fadd2")) .Ship_to_addr_3 = If(IsDBNull(dr("cmp_fadd3")), "", dr("cmp_fadd3")) .Ship_to_addr_4 = If(IsDBNull(dr("cmp_fcity")), "", dr("cmp_fcity")) &amp; " , " &amp; _ If(IsDBNull(dr("StateCode")), "", dr("StateCode")) .Ship_to_country = If(IsDBNull(dr("cmp_fcounty")), "", dr("cmp_fcounty")) .Oe_po_no = dr("ord_no") End With ''//wsPartDepotSalesOrd.OrderHeader.Status 'readonly errNum = wsPartDepotSalesOrd.OrderHeader.Insert(TrxEnums.OeOrderTypeEnum.Order, "", billToCompany, "", dr("ord_dt"), errMsg) If errNum &lt;&gt; 0 Then Console.WriteLine("Error Creating OE header:" &amp; errMsg) Else Console.WriteLine("Created OE#" &amp; wsPartDepotSalesOrd.OrderHeader.Ord_no) End If End If poNum = dr("ord_no") ''//if error then skip to the next loop iteration until the next PO # and it gets inserted ok If errNum &lt;&gt; 0 Then Continue For End If lineNum = If(IsDBNull(dr("line_no")), Now(), dr("line_no")) itemNum = dr("item_no").ToString qtyOrd = If(IsDBNull(dr("qty_ordered")), 0, CDbl(dr("qty_ordered"))) requestDate = If(IsDBNull(dr("request_dt")), Now(), dr("request_dt")) promiseDate = If(IsDBNull(dr("promise_dt")), Now(), dr("promise_dt")) itemPrice = If(IsDBNull(dr("price")), 0, dr("price")) If itemNum.Length &gt; 0 And qtyOrd &lt;&gt; 0 Then CreateLine(wsPartDepotSalesOrd, itemNum, qtyOrd, 0, requestDate, requestDate, promiseDate, itemPrice, poNum) ''//mark as processed, even if above fails. any lines that fail will be added to SO in parts depot by hand. markPoLineAsProcessed(dbName, dbServer, poNum, lineNum) End If Next poNum = "" i = +1 If Not IsNothing(wsConn) Then wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg) wsConn.Dispose() End If If Not IsNothing(wsPartDepotSalesOrd) Then wsPartDepotSalesOrd.Dispose() wsConn = Nothing wsPartDepotSalesOrd = Nothing Next Console.WriteLine("DONE") Catch ex As Exception Console.WriteLine("Exception processing part depot: " &amp; ex.Message) Finally Try ''//cleanup If Not IsNothing(wsPartDepotSalesOrd) Then wsPartDepotSalesOrd.Dispose() wsPartDepotSalesOrd = Nothing End If If Not IsNothing(wsConn) Then wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg) wsConn.Dispose() wsConn = Nothing End If Catch ex As Exception Console.WriteLine("Exception exiting part depot: " &amp; ex.Message) End Try End Try End Function Private Function GetCustomer(ByVal CustomerNum As String, ByVal db As String, ByVal server As String) As DataTable Dim cn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand Dim da As New SqlClient.SqlDataAdapter Dim ds As New DataSet Try cn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=" &amp; db &amp; ";server=" &amp; server cn.Open() cmd = cn.CreateCommand cmd.Parameters.Add(New SqlClient.SqlParameter("@cusnum", CustomerNum)) cmd.CommandText = "select cmp_name,cmp_fadd1,coalesce(debnr,crdnr) as CusNum from dbo.cicmpy where ltrim(debnr) = @cusnum or ltrim(crdnr) = @cusnum" cmd.CommandType = CommandType.Text da.SelectCommand = cmd da.Fill(ds) If ds.Tables.Count &gt; 0 Then Return ds.Tables(0) End If Return Nothing Finally If Not IsNothing(cmd) Then cmd.Dispose() If Not IsNothing(cn) Then cn.Dispose() If Not IsNothing(da) Then da.Dispose() End Try End Function Private Function GetPoDataset(ByVal db As String, ByVal server As String) As DataSet Dim cn As New SqlClient.SqlConnection Dim ds As New DataSet Dim dsa As New SqlClient.SqlDataAdapter Dim cmd As New SqlClient.SqlCommand Try Static Dim SQL As String = ConfigurationManager.AppSettings("getPoforPartsDepotSQL") cn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=" &amp; db &amp; ";server=" &amp; server cn.Open() cmd.Connection = cn cmd.CommandType = CommandType.Text cmd.CommandText = SQL dsa.SelectCommand = cmd dsa.Fill(ds) Return ds Catch Throw Finally If Not IsNothing(ds) Then ds.Dispose() If Not IsNothing(cmd) Then cmd.Dispose() If Not IsNothing(cn) Then cn.Close() If Not IsNothing(cn) Then cn.Dispose() End Try End Function Private Function OpenWiSysConn(ByVal dbName As String, ByVal dbServer As String, ByVal useTran As Boolean) As Boolean Try Dim errMsg As String = "" wsConn.Parameters(dbServer, dbName, "MacMSS") If wsConn.OpenWisysConnection(useTran, errMsg) &lt;&gt; 0 Then Console.WriteLine("Error processing part depot: " &amp; errMsg) Return False End If Return True Catch Throw End Try End Function Private Function CreateLine(ByVal p_oOEObj As Wisys.Oe.OrderEntryTables, ByVal partNum As String, ByVal qtyOrdered As Double, ByVal qtyToShip As Double, ByVal RequestDate As Date, ByVal RequestShipDate As Date, ByVal PromiseDate As Date, ByVal price As Double, ByVal PONum As String) As Boolean Dim OeLine As OEORDLIN Dim p_sRtnErrMsg As String = "" Dim p_lRtnVal As Long Dim p_lRtnLineNumber As Long With p_oOEObj ''//p_lRtnVal = .OrderHeader.Read(TrxEnums.OeOrderTypeEnum.Order, p_sRtnOrder, True, True, True, p_bRtnRecFound, p_sRtnErrMsg) OeLine = .OrderHeader.OrderLines.Add(TrxEnums.OrderLineType.InventoryItem, partNum.ToUpper, "", qtyOrdered, qtyToShip, price, price, RequestDate, PromiseDate, RequestShipDate, True, p_sRtnErrMsg) p_lRtnVal = OeLine.Insert(p_lRtnLineNumber, p_sRtnErrMsg) If p_lRtnVal = 0 Then Return True End If Console.WriteLine("Error creating sales order line# " &amp; p_lRtnLineNumber &amp; ": " &amp; p_sRtnErrMsg) sendBadPOLineEmailtoDepot("Error creating sales order line for PO# " &amp; PONum &amp; " becuase of an error: " &amp; p_sRtnErrMsg) Return False End With End Function Private Function markPoLineAsProcessed(ByVal DB As String, ByVal server As String, ByVal poOrdNum As String, ByVal poLineNum As String) As Boolean Dim cn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand Try Static Dim SQL As String = ConfigurationManager.AppSettings("markPoLineAsSendToDepotSQL") cn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=" &amp; DB &amp; ";server=" &amp; server &amp; ";" cn.Open() cmd.Connection = cn cmd.Parameters.Add(New SqlClient.SqlParameter("@poOrdNum", poOrdNum)) cmd.Parameters.Add(New SqlClient.SqlParameter("@poLineNum", poLineNum)) cmd.CommandType = CommandType.Text cmd.CommandText = SQL cmd.ExecuteNonQuery() Return True Catch Throw Finally If Not IsNothing(cmd) Then cmd.Dispose() If Not IsNothing(cn) Then cn.Dispose() End Try End Function Private Function sendBadPOLineEmailtoDepot(ByVal msgText As String) As Boolean Try If ConfigurationManager.AppSettings("EnableSentBadPOMail").ToLower &lt;&gt; "true" Then Return True Dim sMailServer As String = ConfigurationManager.AppSettings("MailServer") Dim mySmtpClient As New System.Net.Mail.SmtpClient(sMailServer) mySmtpClient.UseDefaultCredentials = True mySmtpClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network Dim sTo As String = ConfigurationManager.AppSettings("BadPOMailTo") Dim sFrom As String = ConfigurationManager.AppSettings("BadPOMailFrom") mySmtpClient.Send(sFrom, sTo, msgText, msgText) Return True Catch ex As Exception Console.WriteLine("Exception sending sending bad PO line e-mail to depot: " &amp; ex.Message) Return False End Try End Function End Class </code></pre> <p>Update: I don't want the output to be overwritten, I want it appended. Thus the >> and not ></p> <p>Update: The outlooks the same in the console window, ie. if not redirected to a file. This is the application outputing to this file and only one runs at a time. There doesn't appear to be any bad data in the clients database.</p> <p>I am confident that the code between site is the same. Also, I have made sure there are no extra console.write/writeline creating the problem. </p> <p>Update: I was missing some code that could be relevent, I have updated the code snippet above. </p> <p>Update: I have been running the process "by hand" at my client so I'm sure only one was running. The ProcessPartDepotOrders() is simply called once from sub main(), so I can't see there being any threading issues. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload