{"id":1688,"date":"2016-03-10T15:22:04","date_gmt":"2016-03-10T14:22:04","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=1688"},"modified":"2016-03-10T15:22:04","modified_gmt":"2016-03-10T14:22:04","slug":"net-c-execute-command-line-batch-file-and-process-the-output-line-by-line-line-break-treatment","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=1688","title":{"rendered":".NET C#: Execute command line batch file and process the output line by line (line break treatment)"},"content":{"rendered":"<h1>Problem<\/h1>\n<p>A Batch File should be executed and the output processed line by line. This is especially useful when you want to generate line break treatments.<\/p>\n<h1>Ansatz &#8211; Approach<\/h1>\n<p>The usage of a stream reader helps to process the output line by line.<\/p>\n<h1>Solution &#8211; L\u00f6sung<\/h1>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nProcess p = new Process();\r\n\r\n\/\/ Redirect the output stream of the child process.\r\np.StartInfo.UseShellExecute = false;\r\np.StartInfo.RedirectStandardOutput = true;\r\n\r\np.StartInfo.FileName = &quot;D:\\\\doors_stats\\\\whatschanged.bat&quot;;\r\np.Start();\r\n\r\nStreamReader sr = p.StandardOutput;\r\nstring output = &quot;&quot;;\r\nwhile (!sr.EndOfStream)\r\n{\r\n\t\/\/ Do s.th. with the received line (i.e. concate)\r\n\toutput += sr.ReadLine() + &quot;\\n\\n&lt;br\/&gt;&quot;;\r\n}\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D1688&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Problem A Batch File should be executed and the output processed line by line. This is especially useful when you want to generate line break treatments. Ansatz &#8211; Approach The usage of a stream reader helps to process the output line by line. Solution &#8211; L\u00f6sung Process p = new Process(); \/\/ Redirect the output &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=1688\" class=\"more-link\"><span class=\"screen-reader-text\">.NET C#: Execute command line batch file and process the output line by line (line break treatment)<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,33,3],"tags":[],"class_list":["post-1688","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-programmierung"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-re","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1688"}],"version-history":[{"count":1,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1688\/revisions"}],"predecessor-version":[{"id":1689,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1688\/revisions\/1689"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}