Showing posts with label cmd/bat. Show all posts
Showing posts with label cmd/bat. Show all posts

2011-12-31

One bug in SED.EXE and another in MS-DOS cmd.exe DEL command

That was a fun day, a WTF one (What's The Fun?!). Wasted at least an hour on troubleshooting third party applications... -_-'

Damn'.


Sed.exe temporary file bug


The utility 'sed.exe' (from GnuWin32) helped me in modifying a file during a headless installation process (changing a property in a "web.config" file). Until there, it was fairly cool.


But here comes the less fun part, I noticed that the executable creates a temporary file right in the middle of its working directory. This is a bug listed and commented here:


From what it looks like, the tool may have regressed in Windows 7 again. Unless it's because of the 64 bit system and the WoW emulation...? Anyway.

The temporary file is not that random, first we know where it is located, second, its name is made of 3 known characters 'sed' and 6 random alphanumeric ones. In regular expressions it would be something like

/sed[a-zA-Z0-9]{6}/

So let's rock'n'roll with a workaround. Let's call:

$> DEL /q sed??????

Let's call it in a directory that contains a file sedE1, a file sedE1f8fd, and a file sedE1f8fdBIS. What happens. All three are deleted. WTF?!


Wildcards issue


After further investigations, "sed????" works fine. So what is wrong?

It seems that, as far as wildcards are concerned:

"?????????" <=> "*"

The explanation I found is that DEL works still on the 8.3 character file name model.

So finally the only workaround is to wrap sed.exe into a batch file:


2011-08-16

Process execution timing in MS DOS cmd.exe batch file


Core


Imagine that you are running a process that takes a long time to perform (eg. build, code generation, maintenance batch, file transfer, etc.) and that you want to see how long it takes. You can use the idea from the sample below. I used a simple "sleep" command in place of a real process, but I believe that you will get the idea.


Usage: In order to use the "timediff" command add the two files
timedff-calc.bat and timediff-sub.bat
to a directory that is in your PATH environment variable (eg. "C:\bin").



Helpers


Consider also adding the following batch script to your toolbox:


Testing


Last but not least, please see the timediff-test.bat file for sample invokations and formats supported:


2008-11-15

Launch TightVNC using the Computer Name - or - How to Get IP from Computer Name in MS-DOS cmd.exe batch file





  • First, knowing the name of a computer, we want to get its IP. The script 'GetIpFromName' does that..
  • Second, we need to call `StartVncViewer MyServerName` to start VncViewer..

    See scripts below: