{"id":31193,"date":"2006-05-16T10:00:07","date_gmt":"2006-05-16T10:00:07","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/05\/16\/command-line-redirection-is-performed-by-the-command-line-interpreter\/"},"modified":"2006-05-16T10:00:07","modified_gmt":"2006-05-16T10:00:07","slug":"command-line-redirection-is-performed-by-the-command-line-interpreter","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060516-07\/?p=31193","title":{"rendered":"Command line redirection is performed by the command line interpreter"},"content":{"rendered":"<p>\nThe magic characters like\n<tt>&lt;<\/tt>,\n<tt>&gt;<\/tt>, and\n<tt>|<\/tt>\nin command lines like\n<\/p>\n<pre>\nmyprogram.exe | sort &gt; output.txt\n<\/pre>\n<p>\nare interpreted by the command interpreter <code>CMD.EXE<\/code>;\nthey aren&#8217;t built into the <code>CreateProcess<\/code> function.\n(This is obvious if you think about it.\nThat command line created two processes; which one should\n<code>CreateProcess<\/code> return a handle to?)\n<\/p>\n<p>\nIf you pass a command line like this to <code>CreateProcess<\/code>,\nit will merely run the\n<code>myprogram.exe<\/code> program with the command line arguments\n&#8220;<tt>| sort &gt; output.txt<\/tt>&#8220;.\n(The <code>ShellExecute<\/code> function behaves similarly.)\nIf you want these characters to be interpreted as redirection\noperators, you need to give them to someone who will interpret\nthose characters in the manner you intend:\n<\/p>\n<pre>\ncmd.exe \/C myprogram.exe | sort &gt; output.txt\n<\/pre>\n<p>\nSince different command line interpreters use different syntax,\nyou have to specify which command line interpreter you want to use.\n<\/p>\n<p>\nIf the command line came from the user, you probably want to use\nthe <code>COMSPEC<\/code> variable in order to give the command\nto the user&#8217;s command line interpreter of choice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The magic characters like &lt;, &gt;, and | in command lines like myprogram.exe | sort &gt; output.txt are interpreted by the command interpreter CMD.EXE; they aren&#8217;t built into the CreateProcess function. (This is obvious if you think about it. That command line created two processes; which one should CreateProcess return a handle to?) If you [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-31193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>The magic characters like &lt;, &gt;, and | in command lines like myprogram.exe | sort &gt; output.txt are interpreted by the command interpreter CMD.EXE; they aren&#8217;t built into the CreateProcess function. (This is obvious if you think about it. That command line created two processes; which one should CreateProcess return a handle to?) If you [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/31193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=31193"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/31193\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=31193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=31193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=31193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}