【发布时间】:2013-01-14 13:39:43
【问题描述】:
我正在使用下面的代码来启动一个新进程并使用 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"
谢谢, 杰森
【问题讨论】:
-
Eugene Roshal 是一个优秀的程序员,但 Unicode 从来都不是他的强项。使用库或升级到 7-zip。