VB.NET shell command that throws an exception not found in the file

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

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

I already added the unix2dos command to my environment path on the server.

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

Is there something I'm missing out on?

+4
source share
2 answers

I would recommend doing this as follows:

 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 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 

This is more complicated, but gives you more options for your processes.

+3
source

If sFileCompletePath contains spaces, it can solve it by adding double quotes in it:

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

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

+1
source

All Articles