Execute DOS From Windows Applications (C#)

Sometimes it is convenient to execute a dos script command from a windows application.  If you use C# doing so is not a big deal here is a sample code that should help execute or calling dos commands from a c#.net application:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
strCommand = @"/c   dir /w/a/p";
Process.Start("CMD.exe", strCommand).WaitForExit();
proc.Close();

I know you are probably saying that there are millions of web pages on the internet that give the same information. Well you are right, but the advantage of using ycsoftware.net is that all the codes are fully tested and supported.

What could go wrong with the above code?

The main thing that could go wrong is the DOS Command. How do you handle a space in a filename ? or how do you handle special characters?.  The Answer is: double quotes.

Let say you wanted to run this command.

wmaonly.bat  c:\\my document\yc software\net\m wma file.wma  c:\\mydocument\my new wma file.wma

How do you use the double quotes?

wrong:
@”/c wmaonly.bat  c:\\my document\yc software\net\m wma file.wma  c:\\mydocument\my new wma file.wma”

wrong:
@”/c ” + “wmaonly.bat  c:\\my document\yc software\net\m wma file.wma”  “c:\\mydocument\my new wma file.wma”

wrong:
@”/c ” + “wmaonly.bat ”  + “c:\\my document\yc software\net\m wma file.wma”  “c:\\mydocument\my new wma file.wma”

wrong:
@”/c ” + ‘”wmaonly.bat ”  + “c:\\my document\yc software\net\m wma file.wma”  “c:\\mydocument\my new wma file.wma”‘

right:
@"/c " + ""wmaonly.bat "  + "c:\\my document\yc software\net\m wma file.wma"  "c:\\mydocument\my new wma file.wma""

Note the double quotes

Import Existing PHP Projects to Eclipse

Let’s say you download and extract a project such as Joomla and you want to add it to your namespace.  Intuitively, you would think that you could just copy the extracted folder to your namespace and close and reopen Eclipse and all of a sudden the project magically appears. Guest what?  It does not work that way.

I am not going to curse at Eclipse because simply it is free, but we could benefit from Eclipse having a initialize script that checks for new folder at the root  of the namespace and prompt us to make choice whether or not we want to create a project using this new directory. It is just common sense.

Here are the step that worked for me:
(FYI: eclipse version: 1.2.2.20100216-1730)

1. Copy a .project file from an existing project to your php folder (Joomla in this case)

2. Open .project file and change the name of the project to the new project.

3. Then Open Eclipse and go to File->Import...



4. Select your root folder and then click finish.
That seems to be a lot of work, for something that simple.