Tag Archives: Windows

MS Windows

Escape Characters in Windows Command Line

Escape Characters in Windows’ CMD.EXE doesn’t entirely work for me. I wanted to embed or escape quote characters in a command line, to give to the binPath parameter of sc.exe to create a windows service. But this contribution from John McNelly in the comments did give the solution:

John McNelly •  Jun 4, 2009 @1:10 pm

You can also use ^ as a line continuation character for readability.
To escape an embedded ” use a backslash, useful with paths within “c:\Program Files” :

sc.exe create Foo ^
binPath= "\"C:\Program Files\foo.exe\" \"C:\Program Files\foo.ini\"" ^
displayName= "Hello, world"

Thanks John.

How To Run FitNesse as a Windows Service

Running a Java Program as a Service

Whether by accident or design, the pages and pages and pages of detailed document at http://wrapper.tanukisoftware.com/doc/english/download.jsp make it remarkably difficult to get off the ground with the Java Service Wrapper. Even the simplified version at http://edn.embarcadero.com/article/32068 foxed me.
So here’s the very simple step by step guide to running a Java program as a Windows service. I did it with FitNesse.jar but it’s the same with any jar file.

How to install FitNesse.jar as a Windows Service

  1. Make sure you can run your java jar file from the windows command line. if you can’t do that, go no further till you can.
  2. Choose a directory where your jar file and its bits will live. For instance C:\Program Files\Your Java App\
  3. Download the Community Build Stable Release of the Javawrapper from the download page.
  4. Open your downloaded zip file, and pick out these files from their subdirectories:
    bin/wrapper.exe
    bin/InstallTestWrapper-NT.bat
    lib/wrapper.dll
    lib/wrapper.jar
    lib/wrappertest.jar
    conf/wrapper.conf
  5. Copy them into the \Your Java App\ directory you created in step 2. Don’t create any subdirectories, just put everything straight into that directory.

Now, the tricky bit is editting your wrapper.conf file. Here are my edits :

# Java Application
wrapper.java.command=java
# Java Main class.  This class must implement the WrapperListener interface
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar)  Add class path elements as needed starting from 1
wrapper.java.classpath.1=wrappertest.jar
wrapper.java.classpath.2=wrapper.jar
wrapper.java.classpath.3=fitnesse.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=
# Java Additional Parameters
wrapper.java.additional.1=
# Application parameters.  Add parameters as needed starting from 1
wrapper.app.parameter.1=fitnesseMain.FitNesseMain
wrapper.app.parameter.2=-p 8080
# Log file to use for wrapper output logging.
wrapper.logfile=wrapperlogs/wrapper.log
# Wrapper Windows NT/2000/XP Service Properties
# Name of the service
wrapper.name=FitNesse
# Display name of the service
wrapper.displayname=FitNesse Server
# Description of the service
wrapper.description=FitNesse is an integration testing wiki and test runner

You’ll notice the following points that you may need to customise for your usage:

  1. My command line to java is just ‘java’ because I have an ordinary install with java in the path.
  2. I’m trying to run Fitnesse.jar
  3. I want FitNesse itself to be passed some parameters -p 8080
  4. I put everything except logs in the one directory, so I have no paths except for the log file.

You’ll want to know how I knew that the main class file for fitnesse.jar is called “fitnesseMain.FitNesseMain“. I did that by first renaming a copy of fitnesse.jar to fitnesse.zip so I could double-click to open it in windows explorer. I read the META-INF/MANIFEST.MF file and looked for the line beginning "Main-Class:"
That gets me to being able to do this from the command line in the directory where I’ve dumped everything:
wrapper -c wrapFitNesse.conf
I renamed the conf file because after all, it’s specific to the jar file I’m trying to run. If it doesn’t work, you probably need to edit the config file again. The point is that all the information needed to launch the jar file is in the conf file.
You should find that Ctrl-C stops the application.

Secondly.

Fortunately this bit’s easier. The inappropriately named InstallTestWrapper-NT.bat just needs a one line edit to work:
set _WRAPPER_CONF_DEFAULT=wrapFitNesse.conf
And then you can run it:
InstallTestWrapper-NT.bat

Automatic Startup of your Java Program as a Windows Service

Voila! For this, I am grateful to tanukisoftware. Now when I open control panel – admin tools – services I find ‘FitNesse’ listed as a service. I set the startup type to automatic and I’m done.

Write to a text file from MS SQL Server

There are several things you need to know to be able to do this.

  1. How to enable ad hoc queries.
    This guy enable-Ad-Hoc-Distributed-Queries shows you how.
  2. How to format the driver string and specify your directory and filename. Like this:
    OpenRowset(‘MSDASQL’, ‘Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=c:\MyDirectoryName;’,’select * from MyTextFile.txt’)
  3. How to create a text file in the right format. This format works:
    “ColumnName1″,”ColumnName2”
    “value11”, “value21”
    “value21”, “value22”

There. That was only slightly unreasonably difficult. Now you can

Select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')

and

Insert into OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')
Values ('Col1', 'Col2')

Switching between Visual Studio .Net and Mono with MonoDevelop

For reasons best not examined too closely I switch between between Mac and PC which, since I earn my crust largely with .Net development, means switching between Visual Studio and MS.Net and MonoDevelop with Mono.

Mono is very impressive, it is not at all a half hearted effort, and it does some stuff that MS haven’t done. But when switching environments, there’s always the occasional gotcha. Here are some that have got me, and some solutions.

Gotcha: Linq Expressions don’t work on Mono

Solution: Add a reference to System.Core to your project.

Question: What version of NUnit is built in to mono?

As of Feb 2011, it’s nunit 2.4.8.