From: Allister L. S. <all...@gm...> - 2008-08-09 21:10:28
|
Hi again everyone, After getting my first introduction to Windows system programming, I finally managed to make the python server run in the background on Vista, and to kill it in the end as well :-) For debugging, however, you might still want to see the python server logs, so I kept the console visible and just wrote a comment in the code on how to hide it. About the error message, I don't see them on GCC 4.2.3 (Kubuntu) anymore. But I still see them on Windows: ********************************** snip: start error log 1>testing.unit-test libs\network\test\bin\msvc-9.0express\debug\link-static\threading-multi\localhost_tests.passed 1>Running 10 test cases... 1>libs/network/test/localhost_tests.cpp(151): error in "text_file_query": check body(response_).length() == size failed [113 != 117] 1>*** 1 failure detected in test suite "http 1.0 localhost tests" 1> 1> libs\network\test\bin\msvc-9.0express\debug\link-static\threading-multi\localhost_tests.exe && echo. > libs\network\test\bin\msvc-9.0express\debug\link-static\threading-multi\localhost_tests.passed 1>...failed testing.unit-test libs\network\test\bin\msvc-9.0express\debug\link-static\threading-multi\localhost_tests.passed... 1>...failed updating 1 target... 1>...updated 2 targets... 1>Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions" 1>Build log was saved at "file://d:\Dev\vc9ws\cpp-netlib\Debug\BuildLog.htm" 1>cpp-netlib - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ********************************** snip: end error log Anyway, here's the patch. Feel free to improve it. Cheers! Allister Index: libs/network/test/localhost_tests.cpp =================================================================== --- libs/network/test/localhost_tests.cpp (revision 48) +++ libs/network/test/localhost_tests.cpp (working copy) @@ -28,6 +28,24 @@ #pragma comment( lib, "shell32" ) // for ShellExecute #pragma comment( lib, "ole32" ) // for CoInitialize, CoUninitialize + SHELLEXECUTEINFO server_info = { + sizeof(server_info), // cbSize + SEE_MASK_NOCLOSEPROCESS, // fMask + NULL, // hwnd + "open", // lpVerb + "python.exe", // lpFile + "cgi_server.py", // lpParameters + "libs\\network\\test\\server", // lpDirectory + SW_SHOWNOACTIVATE, // nShow, use SW_HIDE if you don't like popup windows + 0, // hInstApp + NULL, // lpIDList + NULL, // lpClass + NULL, // hkeyClass + 0, // dwHotKey + NULL, // hIcon + NULL // hProcess + }; + #else #include <unistd.h> // fork, execlp etc. #include <sys/types.h> @@ -48,8 +66,7 @@ // Executes the Python Server // See http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspxfor a description of ShellExecute CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); - BOOST_REQUIRE_MESSAGE( (int)ShellExecute(NULL,"open", "python.exe", " cgi_server.py", - "libs\\network\\test\\server", SW_SHOWNOACTIVATE) > 32, "Python server execution failed.\n" ); + BOOST_REQUIRE_MESSAGE( ShellExecuteEx(&server_info), "Python server execution failed.\n" ); CoUninitialize(); #else // Try general Unix code @@ -57,7 +74,7 @@ BOOST_REQUIRE_MESSAGE(server_child >= 0, "Failed to fork!"); if( server_child == 0 ) { // child process chdir("libs/network/test/server"); - BOOST_REQUIRE_MESSAGE(execlp("xterm", "xterm", "-e", "python cgi_server.py", (char *)NULL) != -1, + BOOST_REQUIRE_MESSAGE(execlp("python", "python", "cgi_server.py", (char *)NULL) != -1, "Python server execution failed!\n"); } else { // parent sleep(1); @@ -218,10 +235,13 @@ BOOST_AUTO_TEST_CASE(server_kill) { // TODO: For automation of regression testing, the windows need to be killed here. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) - // Windows Kill code not implemented + UINT exitcode = 0; + BOOST_REQUIRE_MESSAGE( TerminateProcess(server_info.hProcess, exitcode), + "Failed to shutdown local server!\n" ); + CloseHandle(server_info.hProcess); #else // This code causes a "fatal error" report for this test case. - //kill(server_child, SIGINT); + kill(server_child, SIGTERM); //waitpid(server_child, 0, 0); #endif } |