我正在尝试使用Process调用外部程序:
Dim strExe As String = "E:\Projects\Common Files\mktorrent.exe" Dim p As New Process Dim pinfo As New ProcessStartInfo pinfo.UseShellExecute = False pinfo.RedirectStandardOutput = True pinfo.Arguments = " -a http://blah.com/announce.PHP -l " & FileSizeMarker & " " & fn pinfo.FileName = strExe pinfo.WorkingDirectory = fn.Substring(0,fn.LastIndexOf("\")) pinfo.WindowStyle = ProcessWindowStyle.Normal pinfo.CreateNoWindow = True p.StartInfo = pinfo p.Start()
问题在于文件名(上面的变量fn).如果它有空格,命令会阻塞 – 没有空格,它可以正常工作.我试过添加1,2或3个引号,如下所示:
fn = Chr(34) & Chr(34) & Chr(34) & fn & Chr(34) & Chr(34) & Chr(34)
并且
fn = "\") & Chr(34) & fn & "\"& Chr(34)
和许多其他组合,但它仍然给我一个错误.有关如何让它工作的任何想法?
TIA
请查看以下链接,它在C#中,可能对您有所帮助