Process.start System.nullreferenceexception: Object reference not set to an instance of an object
-
02-03-2021 - |
Вопрос
Ok so I am trying to start the process with the following parameters
When I try to start it though I get an System.nullreferenceexception: Object reference not set to an instance of an object
What am I doing wrong?
Dim exepath As String = Application.StartupPath + "\bin\ffmpeg.exe"
Dim sr As StreamReader
Dim cmd As String = " -i """ + input + """ -ar 22050 -y """ + output + """"
Dim ffmpegOutput As String
proc.StartInfo.FileName = exepath
proc.StartInfo.Arguments = cmd
proc.StartInfo.UseShellExecute = False
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
proc.StartInfo.RedirectStandardError = True 'redirect ffmpegs output
'to our application
proc.StartInfo.RedirectStandardOutput = True 'we don’t really need this
proc.StartInfo.CreateNoWindow = True
proc.Start()
Решение
Your StreamReader
is not initialized:
Dim sr As StreamReader
Verify you are initializing it before using it furthur in the code.
Edit:
Since you specify that the exception is thrown on the proc.Start()
, I would suggest you to declare a ProcessStartInfo
, and use it with Process.Start()
For example:
Dim l As New ProcessStartInfo
l.FileName = exepath
' ...
Process.Start(l)
Не связан с StackOverflow