{"id":2298,"date":"2018-08-30T13:51:41","date_gmt":"2018-08-30T05:51:41","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=2298"},"modified":"2018-08-30T13:51:41","modified_gmt":"2018-08-30T05:51:41","slug":"tont-42073-%e5%85%b3%e4%ba%8e%e9%a2%84%e7%95%99%e6%96%87%e4%bb%b6%e5%90%8dnul%e5%92%8ccon%e7%9a%84%e6%95%85%e4%ba%8b","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/2298","title":{"rendered":"TONT 42073 \u5173\u4e8e\u9884\u7559\u6587\u4ef6\u540dNUL\u548cCON\u7684\u6545\u4e8b"},"content":{"rendered":"<p>\u8fc7\u53bb\u4e0e\u73b0\u5728\uff0c\u5f53\u4e0b\u4e0e\u5c06\u6765\uff0c\u90fd\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20031022-00\/?p=42073\" target=\"_blank\" rel=\"noopener\">https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20031022-00\/?p=42073<\/a><\/p>\n<p>Set the wayback machine to DOS 1.0.<\/p>\n<p>\u8ba9\u6211\u4eec\u628a\u65f6\u95f4\u62e8\u56deDOS 1.0\u7684\u65f6\u4ee3\u3002<\/p>\n<p>DOS 1.0 didn&#8217;t support subdirectories, lowercase, or filenames longer than 8.3.<\/p>\n<p>DOS 1.0\u4e0d\u652f\u6301\u5b50\u76ee\u5f55\uff0c\u5c0f\u5199\u6587\u4ef6\u540d\uff0c\u6216\u8005\u6bd48.3\u683c\u5f0f\uff08\u8bd1\u6ce8\uff1a\u5373\u6587\u4ef6\u540d\u6700\u957f\u4e3a8\u4e2a\u5b57\u7b26\u3001\u6269\u5c55\u540d\u6700\u957f\u4e3a3\u4e2a\u5b57\u7b26\u7684\u6587\u4ef6\u540d\u683c\u5f0f\uff09\u66f4\u957f\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>When you ran the assembler (or compiler if you were really fancy) the conversation went something like this:<\/p>\n<p>\u5f53\u4f60\u8fd0\u884c\u67d0\u4e2a\u6c47\u7f16\u5668\uff08\u6216\u8005\u5f88\u6709\u60f3\u8c61\u529b\u7684\u8bdd\uff0c\u7f16\u8bd1\u5668\uff09\uff0c\u4eba\u673a\u5bf9\u8bdd\u5927\u6982\u662f\u4e0b\u9762\u8fd9\u6837\u7684\uff1a<\/p>\n<p>A&gt;asm foo <em>the &#8220;.asm&#8221; extension on &#8220;foo&#8221; is implied<\/em><span style=\"text-decoration: underline;\"><em>\uff08\u6587\u4ef6foo\u7684\u6269\u5c55\u540d.asm\u4e3a\u9690\u5f0f\u4f20\u9012\uff09<\/em><\/span><br \/>\nAssembler version blah blah blah <span style=\"text-decoration: underline;\">\u6c47\u7f16\u5668 ver x.xx<\/span><br \/>\nSource file: FOO.ASM <span style=\"text-decoration: underline;\">\u8f93\u5165\u6587\u4ef6\u540d\uff1aFOO.ASM<\/span><br \/>\nListing file [FOO.LST]: just hit Enter to accept the default <span style=\"text-decoration: underline;\">\u5217\u8868\u6587\u4ef6\u540d [FOO.LST]\uff1a\u6309\u56de\u8f66\u952e\u4f7f\u7528\u9ed8\u8ba4\u503cFOO.LST<\/span><br \/>\nObject file [FOO.OBJ]: just hit Enter to accept the default <span style=\"text-decoration: underline;\">\u5bf9\u8c61\u6587\u4ef6\u540d [FOO.OBJ]\uff1a\u6309\u56de\u8f66\u952e\u4f7f\u7528\u9ed8\u8ba4\u503cFOO.OBJ<\/span><br \/>\nAssembler cranks away <span style=\"text-decoration: underline;\">\u6c47\u7f16\u5668\u8dd1\u53bb\u5e72\u6d3b\u4e86<\/span><\/p>\n<p>You only had to type the base name of the file; the &#8220;.LST&#8221; and &#8220;.OBJ&#8221; extensions were appended automatically. In fact, I don&#8217;t think you could disable the extensions; they were always added.<\/p>\n<p>\u4f60\u53ea\u9700\u8981\u8f93\u5165\u6587\u4ef6\u7684\u4e3b\u540d\u5c31\u53ef\u4ee5\u4e86\uff0c\u6269\u5c55\u540d.LST\u548c.OBJ\u662f\u81ea\u52a8\u52a0\u4e0a\u53bb\u7684\u3002\u5b9e\u9645\u4e0a\uff0c\u60f3\u4e0d\u52a0\u4e0a\u4e5f\u4e0d\u884c\uff0c\u4e0d\u7ba1\u600e\u4e48\u505a\u90fd\u662f\u4f1a\u52a0\u4e0a\u53bb\u7684\u3002<\/p>\n<p>But what if you didn&#8217;t want a listing file? The assembler demanded a filename, and if you didn&#8217;t type any filename at all, it created one with the same basename as your source file.<\/p>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u4e0d\u60f3\u8981\u5217\u8868\u6587\u4ef6\u8be5\u600e\u4e48\u529e\u5462\uff1f\u6c47\u7f16\u5668\u65e0\u8bba\u5982\u4f55\u90fd\u9700\u8981\u4e00\u4e2a\u6587\u4ef6\u540d\uff0c\u800c\u5982\u679c\u4e0d\u8f93\u5165\u4efb\u4f55\u6587\u4ef6\u540d\u7684\u8bdd\uff0c\u6c47\u7f16\u5668\u4f1a\u521b\u5efa\u4e00\u4e2a\u4e0e\u4f60\u7684\u6e90\u4ee3\u7801\u6587\u4ef6\u4e3b\u540d\u4e00\u6837\u7684\uff08\u5e26\u6709.LST\u540e\u7f00\u7684\uff09\u5217\u8868\u6587\u4ef6\u3002<\/p>\n<p>That&#8217;s where the magic filenames come in. Suppose you wanted the listing file to go straight to the printer. You didn&#8217;t want to create a file on your floppy drive because there might not be enough space to hold it, or just because you didn&#8217;t want to waste the time creating a file just to delete it anyway. So you typed &#8220;PRN&#8221; as the filename.<\/p>\n<p>\u5230\u8fd9\u4e00\u6b65\u300e\u795e\u5947\u6587\u4ef6\u540d\u300f\u5c31\u4f53\u73b0\u51fa\u5b83\u7684\u4f5c\u7528\u4e86\u3002\u5047\u8bbe\u4f60\u60f3\u8ba9\u5217\u8868\u6587\u4ef6\u76f4\u63a5\u88ab\u9001\u5230\u6253\u5370\u673a\uff08\u6253\u5370\u51fa\u6765\uff09\uff0c\u53c8\u4e0d\u60f3\u5728\u8f6f\u76d8\u4e0a\u521b\u5efa\u8fd9\u4e48\u4e00\u4e2a\u6587\u4ef6\uff0c\u56e0\u4e3a\u53ef\u80fd\u6ca1\u6709\u8db3\u591f\u7684\u7a7a\u95f4\uff0c\u4e5f\u53ef\u80fd\u53ea\u662f\u4e0d\u60f3\u6d6a\u8d39\u65f6\u95f4\u5220\u6389\u8fd9\u4e2a\u773c\u4e0b\u5e76\u6ca1\u6709\u4ec0\u4e48\u7528\u7684\u6587\u4ef6\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u7528PRN\u4f5c\u4e3a\u6587\u4ef6\u540d\u3002<\/p>\n<p>Now, the assembler doesn&#8217;t know about these magic filenames. So the assembler will try to create the file &#8220;PRN.LST&#8221; and then start writing to it. Little does the assembler realize that the output is actually going to the printer.<\/p>\n<p>\u6b64\u65f6\uff0c\u6c47\u7f16\u5668\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e2a\u300e\u795e\u5947\u6587\u4ef6\u540d\u300f\u7684\u5e95\u7ec6\uff0c\u53ea\u662f\u7167\u5e38\u5c1d\u8bd5\u521b\u5efa\u6587\u4ef6PRN.LST\u7136\u540e\u5f00\u59cb\u5411\u91cc\u9762\u5199\u5165\u6570\u636e\uff0c\u5168\u7136\u4e0d\u77e5\u8f93\u51fa\u76f4\u63a5\u90fd\u88ab\u5bfc\u5411\u4e86\u6253\u5370\u673a\u3002<\/p>\n<p>If you wanted to discard the output entirely, you would type &#8220;NUL&#8221;, of course. And if you wanted it to go to the screen, you would type &#8220;CON&#8221;.<\/p>\n<p>\u5982\u679c\u5e72\u8106\u4e0d\u60f3\u8981\u4efb\u4f55\u8f93\u51fa\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u53ef\u4ee5\u4f7f\u7528NUL\u4f5c\u4e3a\u6587\u4ef6\u540d\u3002\u6216\u8005\u60f3\u76f4\u63a5\u5c06\u8f93\u51fa\u6253\u5370\u5728\u5c4f\u5e55\u4e0a\uff0c\u53ef\u4ee5\u8f93\u5165\u6587\u4ef6\u540dCON\u3002<\/p>\n<p>Now, if you followed closely, you can see that the above story explains two things already:<\/p>\n<p>\u5230\u6b64\u4e3a\u6b62\uff0c\u5982\u679c\u770b\u5f97\u8db3\u591f\u4ed4\u7ec6\u7684\u8bdd\uff0c\u4f60\u4f1a\u53d1\u73b0\u4ee5\u4e0a\u4f8b\u5b50\u5df2\u7ecf\u989d\u5916\u89e3\u91ca\u4e86\u4e24\u4ef6\u4e8b\uff1a<\/p>\n<ul>\n<li>Why are the magic filenames magical even if I add an extension?<br \/>\nAnswer: If an extension removed the magic, then when the assembler added &#8220;.LST&#8221; to the filename, it would no longer be recognized as magical, thereby defeating the purpose of the magic.<\/li>\n<li>\u4e3a\u4ec0\u4e48\u8fd9\u4e9b\u300e\u795e\u5947\u6587\u4ef6\u540d\u300f\u52a0\u4e86\u6269\u5c55\u540d\u4f9d\u65e7\u6709\u6548\uff1f<br \/>\n\u7b54\uff1a\u5982\u679c\u52a0\u4e86\u6269\u5c55\u540d\u5c31\u5931\u6548\u4e86\uff0c\u90a3\u4e48\u5f53\u6c47\u7f16\u5668\u4e3a\u6587\u4ef6\u540d\u6dfb\u52a0.LST\u540e\u7f00\u65f6\uff0c\u7cfb\u7edf\u5c31\u65e0\u6cd5\u5c06\u5176\u8fa8\u8bc6\u4e3a\u300e\u795e\u5947\u300f\u7684\u6587\u4ef6\u540d\uff0c\u4e5f\u5c31\u5931\u53bb\u4e86\u79f0\u5176\u4e3a\u300e\u795e\u5947\u300f\u7684\u610f\u4e49\u3002<\/li>\n<li>Why do these magic files exist in every directory?<br \/>\nAnswer: Because DOS 1.0 didn&#8217;t have subdirectories. There was only one directory, which today we would call the root directory, but back then, since there was no such thing as a subdirectory, there was no need to talk about directories in the first place, much less give the only one you have a name. It was just called &#8220;the files on your disk&#8221;. If magic files didn&#8217;t work in subdirectories, then when you tried to, for example, chdir into a subdirectory and then run the assembler, you wouldn&#8217;t be able to type &#8220;NUL&#8221; as the filename and get the magic.<\/li>\n<li>\u4e3a\u4ec0\u4e48\u8fd9\u4e9b\u300e\u795e\u5947\u6587\u4ef6\u300f\u5728\u6bcf\u4e2a\u76ee\u5f55\u4e2d\u90fd\u5b58\u5728\uff1f<br \/>\n\u7b54\uff1a\u56e0\u4e3aDOS 1.0\u4e0d\u652f\u6301\u5b50\u76ee\u5f55\u3002\u6574\u4e2a\u78c1\u76d8\u53ea\u6709\u4e00\u4e2a\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u5982\u4eca\u6240\u77e5\u7684\u300e\u6839\u76ee\u5f55\u300f\uff0c\u4f46\u90a3\u4e2a\u65f6\u5019\uff0c\u56e0\u4e3a\u6839\u672c\u6ca1\u6709\u300e\u5b50\u76ee\u5f55\u300f\u8fd9\u79cd\u4e1c\u897f\uff0c\u300e\u76ee\u5f55\u300f\u4e00\u8bf4\u4e5f\u5c31\u65e0\u4ece\u8c08\u8d77\uff0c\u800c\u8fd9\u4e9b\u300e\u795e\u5947\u6587\u4ef6\u300f\u4e5f\u53ea\u5b58\u5728\u4e00\u4efd\u800c\u5df2\u3002\u90a3\u4e2a\u65f6\u5019\uff0c\u53ea\u6709\u300e\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u300f\u4e00\u8bf4\u3002\u5982\u679c\u300e\u795e\u5947\u6587\u4ef6\u300f\u5728\u5b50\u76ee\u5f55\u91cc\u5c31\u4e0d\u597d\u4f7f\u4e86\uff0c\u90a3\u4e48\uff0c\u6bd4\u5982\u8bf4\u4f60\u6539\u53d8\u76ee\u5f55\u5230\u67d0\u4e2a\u5b50\u76ee\u5f55\u91cc\uff0c\u7136\u540e\u8fd0\u884c\u6c47\u7f16\u5668\u7684\u8bdd\uff0c\u5c31\u6ca1\u6709\u529e\u6cd5\u4f7f\u7528NUL\u4f5c\u4e3a\u6587\u4ef6\u540d\u6765\u4f53\u4f1a\u5176\u795e\u5947\u4e4b\u5904\u4e86\u3002<\/li>\n<\/ul>\n<p>But why do we carry these magic filenames forward even today?<\/p>\n<p>\u8bf4\u5f97\u597d\uff0c\u4f46\u8fd9\u4e9b\u300e\u795e\u5947\u6587\u4ef6\u300f\u4e3a\u4ec0\u4e48\u53c8\u4f1a\u4e00\u8def\u6d3b\u5230\u4eca\u5929\u5462\uff1f<\/p>\n<p>Because everybody still relies on them. Just look at all the batch files that do things like redirect to &gt;NUL or test if a directory exists by asking &#8220;if exist directoryname\\nul&#8221;, or all the documentation that says to create a file with &#8220;copy CON &#8230;&#8221;.<\/p>\n<p>\u56e0\u4e3a\u6240\u6709\u4eba\u4ecd\u7136\u4f9d\u8d56\u5b83\u4eec\uff08\u6765\u505a\u4e00\u4e9b\u7279\u5b9a\u7684\u4e8b\u60c5\uff09\u3002\u968f\u4fbf\u627e\u4e2a\u6279\u5904\u7406\u6587\u4ef6\uff0c\u91cc\u9762\u5927\u6982\u90fd\u4f1a\u6709\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u7684 &gt;NUL\uff0c\u6216\u8005\u7528\u4e8e\u5224\u65ad\u67d0\u4e2a\u76ee\u5f55\u662f\u5426\u5b58\u5728\u7684IF EXIST \u76ee\u5f55\u540d\\NUL\uff0c\u8fd8\u6709\u5404\u79cd\u5404\u6837\u7684\u6587\u6863\u4e2d\u4f1a\u6559\u4f60\u7528\u300eCOPY CON &#8230;\u300f\u6765\u521b\u5efa\u6587\u4ef6\u4e4b\u7c7b\u7684\u4e8b\u60c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fc7\u53bb\u4e0e\u73b0\u5728\uff0c\u5f53\u4e0b\u4e0e\u5c06\u6765\uff0c\u90fd\u662f\u4e00\u6837\u7684\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2298","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=2298"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2298\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=2298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=2298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=2298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}