]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/console/console.cpp
don't bounce back events to the text control recursively as this results in infinite...
[wxWidgets.git] / samples / console / console.cpp
index 5e05c0e7b46cda56f0ccccc37aa0b0af7984c2ce..27016fc935cf4dbc56dd451ce861eafecd8efc5d 100644 (file)
@@ -539,7 +539,7 @@ static void TestExecute()
     #define COMMAND "echo hi"
     #define ASYNC_COMMAND "xclock"
     #define SHELL_COMMAND "echo hi from shell"
-    #define REDIRECT_COMMAND COMMAND "cat -n Makefile"
+    #define REDIRECT_COMMAND "cat -n Makefile"
 #elif defined(__WXMSW__)
     #define COMMAND "command.com /c echo hi"
     #define ASYNC_COMMAND "notepad"
@@ -565,8 +565,13 @@ static void TestExecute()
 
     wxPrintf(_T("Testing async wxExecute: "));
     fflush(stdout);
-    if ( wxExecute(ASYNC_COMMAND) != 0 )
+    int pid = wxExecute(ASYNC_COMMAND);
+    if ( pid != 0 )
+    {
         wxPuts(_T("Ok (command launched)."));
+        if ( wxKill(pid) == -1 )
+            wxPuts("ERROR: failed to kill child process.");
+    }
     else
         wxPuts(_T("ERROR."));
 
@@ -578,10 +583,25 @@ static void TestExecute()
     }
     else
     {
-        unsigned count = output.GetCount();
-        for ( unsigned n = 0; n < count; n++ )
+        // don't show too much output, MAX_LINES is enough
+        static const unsigned MAX_LINES = 20;
+
+        const unsigned count = output.size();
+        for ( unsigned n = 0;
+              n < (count > MAX_LINES ? MAX_LINES/2 : count);
+              n++ )
         {
-            wxPrintf("%04u:\t%s\n", n, output[n]);
+            wxPrintf("%04u:\t%s\n", n + 1, output[n]);
+        }
+
+        if ( count > MAX_LINES )
+        {
+            wxPrintf("... skipping %u lines...\n", count - MAX_LINES);
+
+            for ( unsigned n = count - MAX_LINES/2; n < count; n++ )
+            {
+                wxPrintf("%04u:\t%s\n", n + 1, output[n]);
+            }
         }
 
         wxPuts(_T("Ok."));