Save exe output to text file realtime - c++

I have an exe file that connects to a server and outputs results in realtime. Is there any way, using windows, I can store the result of this exe output to a text file, with it updating in semi-realtime? I've tried example.exe > log.txt, but it returns
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at MinecraftClient.ConsoleIO.Write(String text)
at MinecraftClient.ConsoleIO.WriteLine(String line)
at MinecraftClient.McTcpClient.OnConnectionLost(DisconnectReason reason, String message)
at MinecraftClient.Protocol.Handlers.Protocol18Handler.Updater()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

You can use something like that:
mycommand.exe param 2>&1 > myfile.txt
And it will create the myfile.txt at startup and fill it.
The 2 correspond to error log, and &1 add basic log (not debug).
More informations

Related

VS 2017 Test Explorer window null reference exception

So basically when I open my solution with nunit3 & specflow, selenium UI tests in VS 2017 (15.3.2.) I get the following exception and error on test explorer window:
Is there a way to fix this? There is a work around but its ridiculous... If I start VS 2017 without any project and then open the project from recent- its working OK.
An exception was encountered while constructing the content of this frame. This information is also logged in "C:\Users\USER\AppData\Roaming\Microsoft\VisualStudio\15.0_6ae63cad\ActivityLog.xml".
Exception details:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TestWindow.VsHost.TestWindowToolWindow.InvokeSwapInRealTestWindow(String eventName)
at Microsoft.VisualStudio.TestWindow.VsHost.TestWindowToolWindow.OnToolWindowCreated()
at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Type toolWindowType, Int32 id, UInt32 flags)
at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Type toolWindowType, Int32 id, ProvideToolWindowAttribute tool)
at Microsoft.VisualStudio.Shell.Package.FindToolWindow(Type toolWindowType, Int32 id, Boolean create, ProvideToolWindowAttribute tool)
at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Guid& toolWindowType, Int32 id)
at Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsToolWindowFactory.CreateToolWindow(Guid& toolWindowType, UInt32 id)
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()
ActivityLog.xml content:
<entry>
<record>678</record>
<time>2017/09/15 12:43:31.678</time>
<type>Error</type>
<source>VisualStudio</source>
<description>Construction of frame content failed.
Frame identifier: ST:0:0:{e1b7d1f8-9b3c-49b1-8f4f-bfc63a88835d}
Frame caption: Test Explorer
Exception details:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TestWindow.VsHost.TestWindowToolWindow.InvokeSwapInRealTestWindow(String eventName)
at Microsoft.VisualStudio.TestWindow.VsHost.TestWindowToolWindow.OnToolWindowCreated()
at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Type toolWindowType, Int32 id, UInt32 flags)
at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Type toolWindowType, Int32 id, ProvideToolWindowAttribute tool)
at Microsoft.VisualStudio.Shell.Package.FindToolWindow(Type toolWindowType, Int32 id, Boolean create, ProvideToolWindowAttribute tool)
at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Guid& toolWindowType, Int32 id)
at Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsToolWindowFactory.CreateToolWindow(Guid& toolWindowType, UInt32 id)
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()</description>
</entry>
The issue appears if you have Test Explorer on focus upon start up.
The temp solution is to click on another TAB (Solution explorer) before closing VisualStudio so the focus won't be on TestExplorer on startup.
Ref: https://developercommunity.visualstudio.com/content/problem/117601/test-explorer-nullreferenceexception-on-startup.html
The issue appears to be fixed (at least I can't any longer reproduce it) with VS2017 update 15.4.1

Sitecore Log File Repeated Error

I have a sitecore 7.2 site and it is upgraded from 6.6, Any ideas what cause the following error to be appears many times in log file:
ManagedPoolThread #3 2015:07:14 10:03:48 ERROR Exception occurred in retryer scope :
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at Sitecore.Data.DataProviders.Retryer.ExecuteNoResult(Action action, Action recover)
at Sitecore.Analytics.Automation.Data.Sql.SqlAutomationProvider.GetDueStates(AutomationStatesDataTable dataTable, Int32 maxEntries)
at Sitecore.Analytics.Automation.AutomationWorker.GetDueStates(AutomationStatesDataTable dataTable)
at Sitecore.Analytics.Automation.AutomationWorker.Process()
at Sitecore.Analytics.Automation.AutomationWorker.<Wakeup>b__4(Object state)
at Sitecore.Threading.ManagedThreadPool.ProcessQueuedItems()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
The reason you see the same error multiple times is because of the retryer which will retry failed database requests a number of times equal to that set in the number of tries param.
Below is the retryer section taken from web.config v7.2:
<!-- RETRYER
When enabled, the Retryer resends failed database requests a specified number of times.
For example, this is useful if you configure a Sitecore instance to support hot failover for database calls.
Default value: disabled="true"
-->
<retryer disabled="true" type="Sitecore.Data.DataProviders.Retryer, Sitecore.Kernel">
<param desc="Number of tries">6</param>
<param desc="Interval between tries">00:00:00.500</param>
<param desc="Log each exception (should be used for debug only)">true</param>
</retryer>
The exception you see is thrown when the Analytics database connection string is incorrect.
Try to connect to the database using SQL Server Management Studio using credentials from this connection strings.
It is displayed multiple times because of Retryer which tries to re-execute the query after failing (see Jason Home answer for more detailed explanation of retryer).

Client Certificate Web Service Call

I have a requirement to call server web service with client certificate. They have provided me one .crt file. I am hosting my project in WindowsServer2008 IIS7.
I install .crt from right click properties, as i can't add certificate to Server Certificates by Complete Certificate Request. I got the error:
CertEnroll::CX509Enrollment::p_InstallResponse: ANSI bad tag value met.
I googled and found nothing on how to install .crt client certificate. Also tried installing as explaining here on step4.
And when i called like this
string certPath = Server.MapPath("../certificate/iot01.servername.crt");
X509Certificate2 cert = new X509Certificate2(certPath);
ws.ClientCertificates.Add(cert);
res = ws.methodName(params);
I got the error:
System.IO.IOException: The handshake failed due to an unexpected packet format. at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.TlsStream.CallProcessAuthentication(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.ConnectStream.WriteHeaders(Boolean async)
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at .....
Is this is related to my certificate installing and calling. Can someone point me where am i gone wrong.
The error clearly mentions "handshake failed". I suspect it is an SSL auth error because of a WSDL format mismatch.
You should check whether the format of your request, and that of the response are the same. They need to match to be able to communicate.
Microsoft Network Monitor can help you figure out the format.

NUnit - System.IO.FileNotFoundException

Im trying to load a .dll into Nunit which I have never used before(NUnit), when I try open the .dll in Nunit I get the following error. I have no idea whats going wrong , Google doesn't turn up much on this. Any suggestions?
System.IO.FileNotFoundException...
Server stack trace:
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at NUnit.Core.CoreExtensions.InstallAdhocExtensions(Assembly assembly)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
at NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage package)
at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.RemoteTestRunner.Load(TestPackage package)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.Load(TestPackage package)
at NUnit.Util.TestDomain.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Util.RemoteTestAgent.AgentRunner.Load(TestPackage package)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [1]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Util.ProcessRunner.Load(TestPackage package)
at NUnit.Util.TestLoader.LoadTest(String testName)
Make sure that there is no development stage assembly in the GloballyAssemblyCache.
In my case, NUnit failed to load Npgsql.Tests.dll.
Npgsql.Tests.dll links to Npgsql.dll. However GAC has another variant of Npgsql.dll with same version.
If assembly has fully qualified reference name like Npgsql, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, .NET runtime tries to search assembly from GAC at first, and then search your local folder (Probes for the assembly). We can it check at msdn How the Runtime Locates Assemblies

log4Net issues with NUnit (Tried v2.5.7, 2.5.2, 2.4.8, 2.4.7)

I'm getting an error (see bottom of post) when running NUnit against a production code assembly. The production code assembly has a reference to a third party framework that uses log4net internally (Specifically, this is SimplyAccounting's SDK). The version of log4net that it uses is 1.2.9.0. Outside of this third party framework which we use via the public api from the dll files, log4net is not part of our production code.
While troubleshooting, I eliminated the reference to the production code assembly from the unit test project and added a reference to the SimplyAccounting SDK. When I do this NUnit pukes out the following error. If the third party reference (or the production code reference) is not in the test project then Nunit runs fine. Any workarounds with a potential log4net conflict would be helpful. I'm using NUnit 2.5.2.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at log4net.Layout.LayoutSkeleton.get_Header()
at log4net.Appender.TextWriterAppender.WriteHeader()
at log4net.Appender.TextWriterAppender.set_Writer(TextWriter value)
--- End of inner exception stack trace ---
Server stack trace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at NUnit.Core.Log4NetCapture.SetAppenderTextWriter(TextWriter writer)
at NUnit.Core.Log4NetCapture.StartCapture()
at NUnit.Core.TextCapture.set_Enabled(Boolean value)
at NUnit.Core.RemoteTestRunner.StartTextCapture(EventListener queue)
at NUnit.Core.RemoteTestRunner.BeginRun(EventListener listener, ITestFilter filter)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.BeginRun(EventListener listener, ITestFilter filter)
at NUnit.Core.ProxyTestRunner.BeginRun(EventListener listener, ITestFilter filter)
at NUnit.Util.TestDomain.BeginRun(EventListener listener, ITestFilter filter)
at NUnit.Util.TestLoader.RunTests(ITestFilter filter)
at NUnit.UiKit.TestSuiteTreeView.RunTests(ITest[] tests, Boolean ignoreCategories)
at NUnit.UiKit.TestSuiteTreeView.RunSelectedTests()
at NUnit.UiKit.TestTree.RunSelectedTests()
at NUnit.Gui.NUnitForm.runButton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
One solution (although pretty disruptive and not solving the root issue) would be to have your production assembly talk to an interface that wraps the SimplyAccount SDK instead of talking directly to it. Then your production code doesn't need to reference the SDK dll and you could test it freely by passing in a fake imlementation of the interface you created.
This has the design benefit of being decoupled from that SDK, but like I said, it could be quite disruptive to your codebase.