gpt4 book ai didi

asp.net - VB.Net 路径中的反斜杠

转载 作者:行者123 更新时间:2023-12-04 18:26:32 26 4
gpt4 key购买 nike

看来我在 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

它返回 ;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

我将添加一个 ffmpeg 标签,因为它也是另一个关于如何调用它和处理文件的示例。

最佳答案

您无需担心反斜杠。反斜杠在 VB 中不像在 C# 中那样是特殊字符。事实上,如果你将它们加倍,你可能会出错。

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

  • 尽量不要重定向 StandardInput,因为您没有向它传递任何东西。

  • 读取 StandardError 以确保它是空的。它可能包含一条错误消息。

  • 我会使用 Debug.WriteLine 来跟踪函数并尝试找出问题开始出现的地方。

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

  • 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

关于asp.net - VB.Net 路径中的反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11087286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com