Clear .TXT Files with a Windows Batch Command

Posted on

Powershell Use this batch command or batch script in the command prompt to clear a text file blank in Windows using the command line. The function ERROR_FUNC does not exist and this throws a blank output towards the file in the parameter below. This should work for any kind of output format.

SET XML ="%CD%\Pathtofile"
SET @ERROR_FUNC. > "%XML%"

The code is best used for clearing log files without the need for VBScript or CScript. Here’s sample code below clearing an XML log file:

@ECHO OFF
SET XML=%CD%\Project\Contents\Main\components.vxml
@ECHO Clearing %XML%\
CRASH_TEST > "%XML%"

@ECHO Writing file %XML%
(
    @ECHO ^<?xml version=^"1.0^" encoding=^"utf-16^"?^>
    @ECHO ^<components xmlns:xsi=^"http://www.w3.org/2001/XMLSchema-instance^" xmlns:xsd=^"http://www.w3.org/2001/XMLSchema^"^>
    @ECHO ^</components^>
) >>"%XML%"

@ECHO Done
PAUSE

Trivial SMTP ASP.NET Winsock Connectivity Issues

Posted on

ASP.NET C#Lately I have been experiencing issues with running SMTP on ASP.NET 1.1 on a Windows Server specifically the Standard edition. It was a trivial issue and very difficult to trace. The problem would appear in just a day and sometimes will disappear for weeks. The issue has been attributed to a Winsock crash (ASP.NET informs this through the error page). I have not found I have not found any blogs that tackle this issue so I hope this post will help others.

This issues are posted by me in StackOverflow and ServerFault :

The server specifications are below and my notes on the issue:

Windows Server Standard on SP2
IIS 7 with ASP.NET 1.1
IIS 6 for SMTP

The server hosts many websites running ASP.NET 1.1. These websites use the built in SMTP server on IIS6.

The SMTP works fine for a while but after a few weeks or months, It will stop sending emails. I tried sending one via Telnet it seems fine so the SMTP server is not the issue.

I tried restarting the Application Pools but it had not effect whatsoever. I also tried restarting IIS 7.0 and IIS 6.0 it still will not send messages.

The only temporary way we found to fix this was to restart the server.

Is there an ASP.NET cache that we can clear or is causing this issue?

UPDATE:

Got the fix!

It was a hunch but I restarted the Print Spooler and DNS Client services in the server and now emails are sent successfully.

But I still do now know why this happens for ASP.NET 1.1 projects.

UPDATE 2:

Issue appeared again today! I got lucky I thought I had to wait weeks to test it again.

I started by restarting the DNS Client service. No effect still cannot send emails. I then restarted the Print Spooler service and to my surprise it was the culprit! ?????????

How is this even, what, why? huh?

I disabled the Print Spooler permanently. Email still works. I do not think we print anything or if the Print Spooler does any other tasks other than printing.

If it does do anything please comment below.

UPDATE 3:

The fix was temporary. I found out today that WINSOCK refused connections from ASP.NET but accepted connections via telnet mail.

Still trying to find out why this is happening.

UPDATE 4:

Well finally made a reboot with the WINSOCK corruption fixes applied. Hope this holds forever and the bug does not reappear.

FINAL UPDATE:

After a few weeks of debugging and fix finding the only workaround for this would be to either reboot the server regularly, move to System.Net.Mail instead of System.Web.Mail or use Microsoft SQL Server DBMail.

Workaround Fix For NSData Crash or Exception During Release in Objective-C

Posted on

I have been moonlighting as an iPhone Developer recently and I can truly say that you will probably spend more time fixing memory leaks in your code than programming for your App in XCode. I was working on a custom (RSS) feed reader and I was determined to keep the memory footprint to less than 30kb because it was a very simple App. I got stuck when I tried to release my feed data inside the NSData class in Cocoa. It crashed even though I tried different methods such as declaring NSURLConnection as an object. This object is probably the largest data stored in memory (can reach about 4MB) in my App because it contains the feed in XML (and not JSON), so it really needs to be released.

 

Here’s how I released the NSData class pointing to a response from NSURLConnection:


NSData *feedData;
feedData = [[NSData alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error]];
feedData = NULL;
[feedData release];

 

You just have to assign NULL to NSData before releasing it. It does work and it minimized my memory use when I checked it in the Leaks Performance Tool in XCode. Even though it works, I am not sure of is why NSData crashes with NSURLConnection explicitly declared as an owned object.