In meinem Programm werde ich alle Adressen in meinem Netzwerk von x.x.x.1 bis x.x.x.255 scannen (pingen). Ich habe den Befehl in cmd getestet, was gut funktioniert, aber nicht vom Programm ausgeführt werden kann.Command Line for-Schleife pausiert während der Ausführung
Ich habe mein Programm erlaubt Fenster erstellen und hält es auch nach dem Ende des Befehls. Der Prozess funktioniert eine Weile, es pingt von x.x.x.1 nach x.x.x.18 und dann bleibt es hängen. Ich habe versucht, manuell ping x.x.x.18, um zu sehen, was speziell für diese Adresse ist ... noch nichts besonderes, nur eine unbelegte Adresse wie x.x.x.2 bis x.x.x.17.
Jeder kann das Problem diagnostizieren? Vielen Dank!
public void PingAllAddressInVirtualNetwork() {
string hotspotAddress = GetHotspotDefaultAddress();
string cmd = "/k \"for /l %i in (1,1,255) do ping " + hotspotAddress.Substring (0, hotspotAddress.Length - 1) + "%i -n 1 -w 15\"";
UnityEngine.Debug.Log ("cmd = "+cmd);
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe", cmd);
processStartInfo.RedirectStandardOutput = true;
//processStartInfo.CreateNoWindow = true;
//processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.UseShellExecute = false;
processStartInfo.StandardOutputEncoding = Encoding.Default;
Process process = Process.Start (processStartInfo);
if (process != null) {
process.WaitForExit();
UnityEngine.Debug.Log ("ping address (scanning) finished.");
}
}
keine Lösung für Ihr Problem aber: Warum don Verwenden Sie [System.Net.NetworkInformation.Ping] (https://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping (v = vs.110) .aspx)? – Fildor
In Bezug auf Ihr Problem: Können Sie versuchen, StandardError auch umzuleiten? Und vielleicht schauen, was ist der ReturnCode, aber ich bezweifle, dass es nützlich sein wird, wenn es nur blockiert ... – Fildor