views:

1362

answers:

2

I am trying to convert one of my unix text files to a dos text file. I am using the following command:

Shell(string.format("unix2dos {0}", sFileCompletePath))

I've already added the unix2dos command in my environment path on the server.

But when I execute the above mentioned command I get a FileNotFound exception even when the file is located on the disk.

Is there anything I am missing out?

+2  A: 

I would recommend doing it this way:

Public Sub ShellandWait(ByVal ProcessPath As String, ByVal Arguments As String)
        Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.Arguments = Arguments
            objProcess.StartInfo.FileName = ProcessPath
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
            objProcess.Start()
            'Wait until it's finished
            objProcess.WaitForExit()
            'Exitcode as String
            Console.WriteLine(objProcess.ExitCode.ToString())
            objProcess.Close()
        Catch ex As Exception
            Console.WriteLine("Could not start process " & ProcessPath & "  " & ex.Message.ToString)
        End Try

    End Sub

It's more complicated but gives you more power over your processes.

Chris
This Worked For me, Thanks
Antony Delaney
+1  A: 

If sFileCompletePath contains spaces, it could solve it by adding double quotes around it:

Shell(String.Format("unix2dos ""{0}""", sFileCompletePath))

If you want to have more control over the process, it might be better to use the example Chris posted.

awe
I did check and found out that there are no spaces in my path. :(
Shail