0

I am using the code below to start a new process and archive files using winrar:

Private Function RunCmd(ParamArray commands As String()) As String
    Dim returnvalue As String = String.Empty

    Dim info As New ProcessStartInfo("cmd")
    info.UseShellExecute = False
    info.RedirectStandardInput = True
    info.RedirectStandardOutput = True
    info.CreateNoWindow = True



    Using process__1 As Process = Process.Start(info)
        Using sw As StreamWriter = process__1.StandardInput
            Using sr As StreamReader = process__1.StandardOutput
                For Each command As String In commands
                    sw.WriteLine(command)
                    IO.File.AppendAllText(workingDir & "\log.txt", command & vbCrLf)
                Next
                sw.Close()
                returnvalue = sr.ReadToEnd()
                sr.Close()
            End Using
        End Using
    End Using

    info = Nothing


    Return returnvalue
End Function

This code is failing to archive files that have unicode characters in their names. What I get back is this: WARNING: No files

If I run the same command in a command prompt manually all works fine. The line that outputs the command to a file outputs the command correctly (with the unicode character present) An example of a command passed to this function is this:

rar.exe u "\\mypath\myRarFile.rar" -m5 -wE:\WorkingDir "\\pathToFile\miljö.txt" 

Thanks, Jason

iasonas
  • 55
  • 7

1 Answers1

0

That fixed my issue:

Private Function RunCmd(ParamArray commands As String()) As String
    Dim returnvalue As String = String.Empty

    Dim info As New ProcessStartInfo("cmd")
    info.UseShellExecute = False
    info.RedirectStandardInput = True
    info.RedirectStandardOutput = True
    info.CreateNoWindow = True

    Using process__1 As Process = Process.Start(info)
        Using sw As StreamWriter = process__1.StandardInput
            Using sr As StreamReader = process__1.StandardOutput
                For Each command As String In commands

                    sw.WriteLine("chcp 65001")

                    sw.WriteLine(command)
                Next
                sw.Close()
                returnvalue = sr.ReadToEnd()
                sr.Close()
            End Using
        End Using
    End Using
    info = Nothing

    Return returnvalue
End Function
iasonas
  • 55
  • 7