{"id":299,"date":"2008-09-04T21:02:34","date_gmt":"2008-09-04T19:02:34","guid":{"rendered":"http:\/\/blog.m-ri.de\/?p=299"},"modified":"2008-09-04T19:55:34","modified_gmt":"2008-09-04T17:55:34","slug":"aufflackern-eines-konsolenfensters-bei-nutzung-system-und-_popen","status":"publish","type":"post","link":"http:\/\/blog.m-ri.de\/index.php\/2008\/09\/04\/aufflackern-eines-konsolenfensters-bei-nutzung-system-und-_popen\/","title":{"rendered":"Aufflackern eines Konsolenfensters bei Nutzung system und _popen"},"content":{"rendered":"<p>Immer wieder kommt die Frage auf, warum sich ein Konsolenfenster kurz \u00f6ffnet wenn man eine Windows Anwendung, wie z.B. Notepad mit den CRT Funktion <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/277bwbdz.aspx\">system<\/a> startet.<\/p>\n<p>Die Antwort ist ganz einfach, dazu muss man einfach mal nicht einmal unbedingt einen Blick in die Sourcen werfen, denn es ist sogar richtig f\u00fcr system dokumentiert in der <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/277bwbdz.aspx\">MSDN<\/a>.<\/p>\n<blockquote><p>The <span><span class=\"keyword\">system<\/span><\/span> function passes <span class=\"parameter\"><em>command<\/em><\/span> to the command interpreter, which executes the string as an operating-system command. <span><span class=\"keyword\">system<\/span><\/span> refers to the <span><span class=\"keyword\">COMSPEC<\/span><\/span> and <span><span class=\"keyword\">PATH<\/span><\/span> environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows 2000 and later). If <span class=\"parameter\"><em>command<\/em><\/span> is NULL, the function simply checks to see whether the command interpreter exists.<\/p><\/blockquote>\n<p>Also kurz und b\u00fcndig: Es wird zwangsl\u00e4ufig immer ein Konsolenfenster ge\u00f6ffnet. Das verschwindet zwar sofort wieder, wenn man eine GUI Applikation startet, aber das kann man vermeiden indem man gleich <em>ShellExecute <\/em>verwendet.<\/p>\n<p>Ganz anders sieht es mit der Doku bei <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/96ayss4b.aspx\">_popen<\/a> aus. <em>_popen <\/em>scheint sich anzubieten, um die Ausgaben eines Tools in eine Datei umzuleiten. Aber auch <em>_popen <\/em>nutzt wie <em>system CMD.EXE \/c <\/em>(<em>COMSPEC<\/em>). Um das heraus zu bekommen muss man allerdings den Source Code der <em>CRT <\/em>zu Rate ziehen. Das bedeutet, dass auch bei Verwendung von <em>_popen <\/em>ein Flackern durch ein Konsolenfenster nicht ausbleibt.<\/p>\n<p>Wie man es richtig macht, wenn man die stdin\/stdout umleiten will findet man in den wohlbekannten Artikeln der MSDN <a href=\"http:\/\/support.microsoft.com\/kb\/190351\">http:\/\/support.microsoft.com\/kb\/190351<\/a>\u00a0und <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms682499.aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/ms682499.aspx<\/a>. Durch die Verwendung von CreateProcess l\u00e4sst sich auch ganz vermeiden, dass der zweite Prozess angezeigt wird.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Immer wieder kommt die Frage auf, warum sich ein Konsolenfenster kurz \u00f6ffnet wenn man eine Windows Anwendung, wie z.B. Notepad mit den CRT Funktion system startet. Die Antwort ist ganz einfach, dazu muss man einfach mal nicht einmal unbedingt einen Blick in die Sourcen werfen, denn es ist sogar richtig f\u00fcr system dokumentiert in der &hellip; <a href=\"http:\/\/blog.m-ri.de\/index.php\/2008\/09\/04\/aufflackern-eines-konsolenfensters-bei-nutzung-system-und-_popen\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eAufflackern eines Konsolenfensters bei Nutzung system und _popen\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19,3,9,27,2],"tags":[370,81,360,61],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-crt","category-programmieren","category-sonstiges","category-vs2008","category-windows-api","tag-c","tag-cmdexe","tag-crt","tag-winapi"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/comments?post=299"}],"version-history":[{"count":0,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/posts\/299\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/media?parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/categories?post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/tags?post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}