VB.Net中的路径中的反斜杠

Léo*_*ier 2 vb.net asp.net path backslash

看起来我在ASP.Net VB.Net中反斜杠似乎不幸运.

我正在尝试使用ffprobe输出一些关于文件的信息,并且我的路径会在包含反斜杠的每个字符串中以一些反斜杠随机剪切.

我调试了这个函数来返回fileToProcess生成的路径:

Function ffprobe_show_format(ByVal arg As String) As String
    Dim myProcess As New System.Diagnostics.Process()
    Dim fileToProcess As String = MapPath(".") & "\temps\" & arg
    myProcess.StartInfo.FileName = MapPath(".") & "\ffprobe.exe"
    myProcess.StartInfo.Arguments = "-show_format " & fileToProcess & " >C:\inetpub\vhosts\mysite.com\httpdocs\absolutefs\ffmpegtemp.txt"
    myProcess.StartInfo.UseShellExecute = False
    myProcess.StartInfo.RedirectStandardInput = True
    myProcess.StartInfo.RedirectStandardOutput = True
    myProcess.Start()
    Dim myStreamWriter As StreamWriter = myProcess.StandardInput
    Dim mystreamreader As StreamReader = myProcess.StandardOutput
    Dim str As String = mystreamreader.ReadToEnd
    Return str & ";" & "FileToProcess=" & fileToProcess & "MapPath(.) AND ffprobe.exe" & MapPath(".") & "\\ffprobe.exe"
End Function
Run Code Online (Sandbox Code Playgroud)

它回来了 ;FileToProcess=C:

这意味着

  • 由于某些错误,我的文件未得到处理
  • 我的路径是在反斜杠切割
  • 然后打破其余的字符串

我是否需要告诉asp.net以另一种方式表示反斜杠?

[编辑]

我不能选择一个答案但是会因为我犯了两个错误而投票: - 要调试,一旦将它放入带有限制大小的SQL变量中,我就读取了我的价值 - 用Newtonsoft.Json解析器获取可能是拒绝一些人.

我是ASP.Net的新手,所以我很难找到一个好的调试方法.所以当我无法在平台上调试时,我终于像往常一样:我已经在一个文本文件中编写了调试变量,并且所有内容都是使用这种方式:

Function ffprobe_show_format(ByVal file As String, ByVal app As String) As String        
    Dim myProcess As New System.Diagnostics.Process()
    myProcess.StartInfo.FileName = app
    Dim argz As String = FormatCommandLine("-show_format", file)
    myProcess.StartInfo.Arguments = argz
    myProcess.StartInfo.UseShellExecute = False
    myProcess.StartInfo.RedirectStandardOutput = True
    myProcess.Start()
    Dim mystreamreader As StreamReader = myProcess.StandardOutput str As String = mystreamreader.ReadToEnd
    MapPath(".") & "/ffprobe.exe"
    Dim objWriter As New System.IO.StreamWriter(MapPath(".") & "\debug.txt")
    objWriter.Write(str)
    objWriter.Close()
    Return str
End Function
Run Code Online (Sandbox Code Playgroud)

我将添加一个ffmpeg标记,因为它也是如何调用它并处理文件的另一个例子.

Ric*_*ich 5

您不必担心反斜杠.反斜杠不是VB中的特殊字符,就像在C#中一样.事实上,如果你把它们加倍,你可能会遇到错误.

很难说出问题出在哪里.尝试缩小范围的一些想法:

  • 尝试不重定向StandardInput,因为您没有传递任何东西.

  • 从StandardError读取以确保它为空.它可能包含错误消息.

  • 我会利用Debug.WriteLine来跟踪函数,并尝试找出问题出现的地方.

  • 这可能无关紧要,但我会在mystreamreader.ReadToEnd之后放置myProcess.WaitForExit.

  • Larry建议使用System.IO.Path是一个很好的建议.

一些根据所有这些匆忙修改了代码:

Function ffprobe_show_format(ByVal arg As String) As String

    Debug.WriteLine("arg: " & arg)

    Dim fileToProcess As String = IO.Path.Combine(MapPath("."), "temps\" & arg)
    Debug.WriteLine("fileToProcess = " & fileToProcess)

    Debug.WriteLine("MapPath AND ffprobe.exe: " & IO.Path.Combine(MapPath(".") & "\\ffprobe.exe"))

    Dim myProcess As New System.Diagnostics.Process()
    myProcess.StartInfo.FileName = IO.Path.Combine(MapPath("."), "\ffprobe.exe")
    myProcess.StartInfo.Arguments = "-show_format " & fileToProcess & " >C:\inetpub\vhosts\mysite.com\httpdocs\absolutefs\ffmpegtemp.txt"
    myProcess.StartInfo.UseShellExecute = False
    'myProcess.StartInfo.RedirectStandardOutput = True
    myProcess.StartInfo.RedirectStandardError = True
    myProcess.Start()
    'Dim str As String = myProcess.StandardOutput.ReadToEnd
    Dim errStr as string = myProcess.StandardError.ReadToEnd
    myProcess.WaitForExit()

    Debug.WriteLine("myProcess exit code = " & myProcess.ExitCode.ToString())
    'Debug.WriteLine("stdOutput: " & str)
    Debug.WriteLine("stdError: " & errStr)

    Return str & ";" & "FileToProcess=" & fileToProcess

End Function
Run Code Online (Sandbox Code Playgroud)