-4
我有這樣的代碼:無法運行命令VB.NET
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox2.Clear()
If TextBox1.Text.Contains(" ") Then
psi = New ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1))
Else
psi = New ProcessStartInfo("C:/Bukkit Runner/run.bat")
End If
Dim systemencoding As System.Text.Encoding
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding
.StandardErrorEncoding = systemencoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
和文本框的命令
If TextBox1.Text.Contains(" ") Then
psi = New ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1))
Else
psi = New ProcessStartInfo(TextBox1.Text$)
End If
Dim systemencoding As System.Text.Encoding
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding
.StandardErrorEncoding = systemencoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
,但我得到這個錯誤,如果我不停止在控制檯: http://prntscr.com/9jvf90
第一個開始命令工作正常。 http://prntscr.com/9jvfqe
我該如何在bat文件中運行命令?
感謝您的回答。但使用此代碼運行時會崩潰。 :( 對不起,我的英語不好。 – Jordytjes