{"id":109407,"date":"2024-02-15T07:00:00","date_gmt":"2024-02-15T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=109407"},"modified":"2024-02-15T08:29:23","modified_gmt":"2024-02-15T16:29:23","slug":"20240215-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240215-00\/?p=109407","title":{"rendered":"Registered command lines are just command lines, not a programming language"},"content":{"rendered":"<p>A customer wanted to register a file extension with a complex command line that goes beyond simple string insertion.<\/p>\n<blockquote class=\"q\">\n<p>When the user double-clicks a <tt>*.xyz<\/tt> file, we want it to run the Contoso program not only with the file name as a command line, but also with an additional command line argument that is a transformation of the file name.<\/p>\n<p>For example, if the user double-clicks <tt>C:\\Users\\<wbr \/>Chris\\<wbr \/>Awesome.xyz<\/tt>, we want to run the command line<\/p>\n<pre style=\"white-space: pre-wrap;\">\"C:\\Program Files\\<wbr \/>Contoso\\<wbr \/>contoso.exe\" -exceptions C:\\Users\\<wbr \/>Chris\\<wbr \/>Awesome.exceptions C:\\Users\\<wbr \/>Chris\\<wbr \/>Awesome.xyz\r\n<\/pre>\n<p>if a file <tt>Awesome.exceptions<\/tt> exists in the same directory as <tt>Awesome.xyz<\/tt>. Otherwise, just launch it without the bonus <tt>-exceptions<\/tt> option.<\/p>\n<p>We tried using <tt>%~dpn1.exceptions<\/tt>, but that just produces the percent sign and stuff. And it still doesn&#8217;t deal with testing whether the exceptions file exists.<\/p>\n<\/blockquote>\n<p>The command line is just a command line with insertions. It is not a programming language. If you want a programming language, you&#8217;ll have to write a program.<\/p>\n<p>For example, you could write a batch file that looks for a <tt>.exceptions<\/tt> file in the same directory as the file whose name was passed on the command line, and then run the <tt>contoso.exe<\/tt> program appropriately based on what you discover.<\/p>\n<pre style=\"white-space: pre-wrap;\">@echo off\r\nif exist \"%~dpn1.exceptions\" (\r\n    echo \"C:\\Program Files\\Contoso\\contoso.exe\" -exceptions \"%~dpn1.exceptions\" \"%1\"\r\n) else (\r\n    echo \"C:\\Program Files\\Contoso\\contoso.exe\" \"%1\"\r\n)\r\n<\/pre>\n<p>You can then use this batch file as the command line.<\/p>\n<pre>\"C:\\Program Files\\Contoso\\Contoso-launcher.cmd\" \"%1\"\r\n<\/pre>\n<p>Of course, this will display a command prompt briefly. You can write a program in a non-console language if that bothers you. At this point, the problem has been reduced to computer programming.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want a programming language, you know where to find one.<\/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":[25],"class_list":["post-109407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you want a programming language, you know where to find one.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109407","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=109407"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109407\/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=109407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=109407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=109407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}