Weil ich nicht sicher bin, was es verursacht, habe ichUm den gesamten Code zu kopieren und einzufügen, tut es mir leid, wenn dies gegen die Regeln verstößt. Dieses Programm wurde in Visual Basic 2010 geschrieben. Verwenden Sie cmd, um Robocopy zu betreiben, und zeigen Sie die Ergebnisse in Echtzeit an. Es macht das, hängt aber nach ein paar Anwendungen, ich bin neu in dieser Codierung und bin mir nicht sicher, wie ich mit Threads umgehen soll, also könnte es das sein, aber ich habe keine Ahnung, wie ich es trotzdem beheben soll.
Wenn mir jemand helfen könnte, wäre ich sehr dankbar :)
Public Class Form1
Private Results As String
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Dim button_click As Integer = 0
Dim myProcess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
Dim Folder_TBC As String
Dim Folder_DES As String
Dim RoboCommand As String
Private Sub UpdateText()
" TextBox_CMDout.Text = Results
TextBox_CMDout.AppendText(System.Environment.NewLine() & Results)
TextBox_CMDout.ScrollToCaret()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If button_click = 0 Then
RoboCommand = Chr(34) + TextBox_FolderTBC.Text + Chr(34) + " " + Chr(34) + TextBox_FolderDes.Text + Chr(34) + " "
If CheckBox_ISF.Checked = True Then RoboCommand = RoboCommand + "/S "
If CheckBox_MUT.Checked = True Then RoboCommand = RoboCommand + "/MT "
If CheckBox_MOV.Checked = True Then RoboCommand = RoboCommand + "/Move "
opencmd()
button_click += 1
End If
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub opencmd()
StartInfo.FileName = "cmd" "starts cmd window
StartInfo.UseShellExecute = False "required to redirect
StartInfo.CreateNoWindow = True "creates no cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.RedirectStandardError = True
myProcess.StartInfo = StartInfo
myProcess.Start()
End Sub
Private Sub CMDAutomate()
"Dim SR As System.IO.StreamReader = myprocess.StandardOutput
"Dim SW As System.IO.StreamWriter = myprocess.StandardInput
myProcess.StandardInput.WriteLine("robocopy " & Folder_TBC & Folder_DES)
myProcess.StandardInput.WriteLine(System.Environment.NewLine())
" SW.WriteLine("exit") "exits command prompt window
While myProcess.StandardOutput.EndOfStream = False
Results = myProcess.StandardOutput.ReadLine()
Invoke(Finished)
End While
"Results = SR.ReadToEnd "returns results of the command window
"SW.Close()
"SR.Close()
"invokes Finished delegate, which updates textbox with the results text
Application.ExitThread()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FolderBrowserDialog1.ShowDialog()
TextBox_FolderTBC.Text = FolderBrowserDialog1.SelectedPath
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
FolderBrowserDialog1.ShowDialog()
TextBox_FolderDes.Text = FolderBrowserDialog1.SelectedPath
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Application.ExitThread()
Application.Exit()
End
End Sub
Ende Klasse
Antworten:
0 für die Antwort № 1Löschen Sie den Text TextBox_CMDout, wenn ein nächster Klick verarbeitet wird. Sie verketten immer wieder alle Ausgaben
Als nächstes denke ich, dass Ihre Lösung viel zu kompliziert für das ist, was Sie tun möchten.
Versuchen Sie dies (und geben Sie die richtigen Parameter in Ihre Textfelder ein). Mehr wird NICHT benötigt und vermeidet Themen wie "Wann beenden Sie den CMD-Befehl?" und ähnlich.
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "Robocopy"
myProcess.StartInfo.Arguments = "/?"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
TextBox_CMDout.Text = myProcess.StandardOutput.ReadToEnd()
myProcess.WaitForExit()
myProcess.Close()