Question Needing to run a command line script from within winforms application

nlraley

Member
Joined
Jul 15, 2010
Messages
7
Programming Experience
Beginner
I am writing an application in which a user is doing a file conversion. I have a set of tools that can perform the conversion on the fly via command line, but I'm not entirely sure of how to go about passing the parameters I need to the command line and running them. Can someone point me to the right direction?

Would I just create a System.Diagnostics.Process and use that? If so how do I do the line by line command? For instance if I need to issue a cd command to change the directory and then execute a command after that how would I do that?
 
Last edited:
Okay, I'm starting to figure this out, its actually quite simple once I did some digging around with regards to the system.diagnostics.process.

Here is what I have:

VB.NET:
Dim conversionProc As New System.Diagnostics.Process()
        Dim folder As String
        Dim kmlFileName As String

        Dim folderPos As Integer

        folder = txtLocation.Text

        kmlFileName = folder.Replace(".shp", ".kml")

        folderPos = folder.LastIndexOf("\")
        folder = folder.Remove(folderPos)

        conversionProc.EnableRaisingEvents = False

        conversionProc.StartInfo.FileName = "CMD.exe"

        conversionProc.StartInfo.Arguments = "cd " + folder + "&ogr2ogr -f KML " + kmlFileName + " " + txtLocation.Text + "&exit"
        conversionProc.Start()
        conversionProc.Kill()

One more question and I'll have this finished. I need to run the bat file located in the install directory of the conversion program. Any idea how I can retrieve where that directory is installed at?
 
Back
Top