我正在尝试使用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#中可能对您有帮助
Word command-line-arguments space issues