以下のコードを使用して、新しいプロセスを開始し、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
このコードは、名前に Unicode 文字を含むファイルをアーカイブできません。私が返すのはこれです:警告:ファイルがありません
コマンドプロンプトで同じコマンドを手動で実行すると、すべて正常に動作します。コマンドをファイルに出力する行は、コマンドを正しく出力します (Unicode 文字が存在します)。この関数に渡されるコマンドの例は次のとおりです。
rar.exe u "\\mypath\myRarFile.rar" -m5 -wE:\WorkingDir "\\pathToFile\miljö.txt"
ありがとう、ジェイソン