我有这段代码:
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文件中运行命令?
答案 0 :(得分:0)
作为一个Minecrafter,我可以清楚地看到你正在尝试运行Bukkit服务器。
也许这会有所帮助?
Private Sub MyCode(sender As Object, e As EventArgs) Handles <stuff>
Try
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox2.Clear()
Textbox_TextChanged(sender,e)
Catch
End
End Try
End Sub
Private Sub Textbox_TextChanged(sender As Object, e As EventArgs) Handles Textbox1.textChanged, Textbox2.TextChanged
Try
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()
Catch
End
End Try
End Sub