{"id":300,"date":"2011-09-11T12:42:01","date_gmt":"2011-09-11T19:42:01","guid":{"rendered":"https:\/\/formidableengineeringconsultants.com\/?p=300"},"modified":"2013-12-09T10:06:10","modified_gmt":"2013-12-09T18:06:10","slug":"in-brazil-we-have-space","status":"publish","type":"post","link":"https:\/\/formidableengineeringconsultants.com\/?p=300","title":{"rendered":"In Brazil, We Have Space &#8211; But In Software&#8230;"},"content":{"rendered":"<p><a href=\"https:\/\/formidableengineeringconsultants.com\/wp-content\/uploads\/2011\/09\/space.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-664 alignleft\" alt=\"space\" src=\"https:\/\/formidableengineeringconsultants.com\/wp-content\/uploads\/2011\/09\/space-224x300.jpg\" width=\"224\" height=\"300\" srcset=\"https:\/\/formidableengineeringconsultants.com\/wp-content\/uploads\/2011\/09\/space-224x300.jpg 224w, https:\/\/formidableengineeringconsultants.com\/wp-content\/uploads\/2011\/09\/space.jpg 670w\" sizes=\"auto, (max-width: 224px) 100vw, 224px\" \/><\/a>In the famous <a href=\"http:\/\/www.aardman.com\/\">Aardman Animations<\/a> short film &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Creature_Comforts\">Creature Comforts<\/a>&#8220;, a variety of zoo animals discuss their lives in the zoo.\u00a0 A Brazilian Lion speaks at length about the virtue of the great outdoors (cf. a zoo) recalling that in Brazil &#8220;<a href=\"http:\/\/www.youtube.com\/watch?v=RSNEKIyZOzg\">We have space<\/a>&#8220;.\u00a0 While space might be a great thing for Brazilian Lions, it turns out that space is a dangerous and difficult reality in path names for computer applications.<\/p>\n<p>In a recent contract, one portion of the work involved running an existing Windows application under <a href=\"http:\/\/www.cygwin.com\/\">Cygwin<\/a>. Cygwin, for the uninitiated, is an emulation of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bash\">bash<\/a> shell and most standard Unix commands. It provides this functionality so you can experience Unix under Windows. The Windows application I was working on\u00a0had been abandoned for several years and customer pressure finally reached a level at which maintenance and updates were required &#8211; nay, <a href=\"http:\/\/www.flickr.com\/photos\/corgi_t\/572815633\/\">demanded<\/a>. Cygwin support was required primarily for internal infrastructure reasons. The infrastructure was a testing framework &#8211; primarily comprising bash shell scripts &#8211; that ran successfully on Linux (for other applications). My job was to get the Windows application re-animated and running under the shell scripts on Cygwin.<\/p>\n<p>It turns out that the Windows application had a variety of issues with <a href=\"http:\/\/www.youtube.com\/watch?v=to2b-CTguRU\">spaces<\/a> in path names. Actually, it had one big issue &#8211; it just didn&#8217;t work when the path names had spaces. The shell scripts had a variety of issues with spaces. Well, one big issue &#8211; they, too, just didn&#8217;t work when the path names had spaces. And it turns out that some applications and operations in Cygwin have issues with spaces, too. Well, that one big issue &#8211; they don&#8217;t like spaces.<\/p>\n<p>Now by &#8220;like&#8221;, I mean that when the path name contains spaces then even using &#8216;\\040&#8217; (instead of the space) or quoting the name (e.g., &#8220;Documents and Settings&#8221;) does not resolve matters and instead merely yields unusual and unhelpful error messages. The behavior was completely unpredictable, as well. For instance, quoting might get you part way through a section of code but then the same quoted name failed when used to call <a href=\"http:\/\/linux.die.net\/man\/2\/stat\">stat<\/a>. It would then turn out that stat didn&#8217;t like spaces in any form (quoted, escaped, <a href=\"http:\/\/2.bp.blogspot.com\/-KpNefuOumFU\/TfJRejG_m3I\/AAAAAAAAAOs\/7T53mtnU-Mk\/s1600\/whatever.jpg\">whatever<\/a>&#8230;).<\/p>\n<p>Parenthetically, I would note that the space problem is widespread. I was doing some <a href=\"http:\/\/www.android.com\">Android<\/a> work and having an odd an unhelpful error displayed (&#8220;invalid command-line parameter&#8221;) when trying to run my application on the emulator under <a href=\"http:\/\/www.eclipse.org\">Eclipse<\/a>. It turns out that<a href=\"http:\/\/stackoverflow.com\/questions\/6638713\/android-emulator-is-not-starting-showing-invalid-command-line-parameter\"> a space in the path name to the Android SDK was the cause<\/a>.\u00a0 Once the space was removed, all was well.<\/p>\n<p>The solution to my problem turned out to be manifold. It involved a mixture of quoting, clever use of <a href=\"http:\/\/cygwin-lite.sourceforge.net\/html\/cygpath.html\">cygpath<\/a> and the Windows API calls <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa364980(VS.85).aspx\">GetLongPathName<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa364989%28v=VS.85%29.aspx\">GetShortPathName<\/a>.<\/p>\n<p>When assigning and passing variables around in shell scripts, quoting a space-laden path or a variable containing a space-laden path,\u00a0\u00a0the solution was\u00a0easy. Just remember to use\u00a0quotes:<\/p>\n<p><strong>THIS=&#8221;${THAT}&#8221;<\/strong><\/p>\n<p>Passing command line options that include path names with spaces tended to be more problematic. The argc\/argv parsers don&#8217;t like spaces.\u00a0 They don&#8217;t like them quoted and don&#8217;t like them escaped.\u00a0 Or maybe the parser likes them but the application doesn&#8217;t.\u00a0In any event, the specific workaround that used was clever manipulation of the path using the cygpath command. The <strong>cygpath -w -s<\/strong> command will translate a path name to the Windows version (with the drive letter and a colon at the beginning) and then shortens the name to the old-style 8+3 limited format thereby removing the spaces. An additional trick is that then, if you need the cygwin style path &#8211; without spaces &#8211; you get the output of the cygpath -w -s and run it through <strong>cygpath -u<\/strong>. Then you get a \/cygdrive\/ style file name with no spaces. There is no other direct path to generating a cygwin Unix style file name without spaces.<\/p>\n<p>These manipulations allow you to get the sort of input you need to the various Windows programs you are using. It is important to note, however, that a Windows GUI application built using standard file browser widgets and the like always passes fully instantiated, space-laden path names. The browser widgets can&#8217;t even correctly parse 8+3 names. Some of the system routines, however, don&#8217;t like spaces. Then the trick is how do you manipulate the names once within the sphere of the Windows application? Well, there are a number of things to keep in mind, the solutions I propose will not work with cygwin Unix-style names and they will not work with relative path names.<\/p>\n<p>Basically, I used the 2 windows API calls <strong>GetLongPathName<\/strong> and <strong>GetShortPathName<\/strong> to manipulate the path. I used GetShortPathName to generate the old-style 8+3 format name that removes all the spaces. This ensured that all system calls worked without a hitch. Then, in order, to display messaging that the end-user would recognize, make sure that the long paths are restored by calling GetLongPathName for all externally shared information. I need to emphasize that these Windows API calls do not appear to work with relative path names. They return an empty string as a result. So you need to watch out for that.<\/p>\n<p>Any combination of all these approaches (in whole or in part) may be helpful to you in resolving any space issues you encounter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the famous Aardman Animations short film &#8220;Creature Comforts&#8220;, a variety of zoo animals discuss their lives in the zoo.\u00a0 A Brazilian Lion speaks at length about the virtue of the great outdoors (cf. a zoo) recalling that in Brazil &#8220;We have space&#8220;.\u00a0 While space might be a great thing for Brazilian Lions, it turns [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[31,15,51],"tags":[25,33,34,46,55,89,52,54,53],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-consulting","category-software","category-software-tips-tricks","tag-code-reuse","tag-consultant","tag-contractor","tag-ideas","tag-linux","tag-software","tag-space","tag-unix","tag-windows"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300"}],"version-history":[{"count":44,"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":666,"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=\/wp\/v2\/posts\/300\/revisions\/666"}],"wp:attachment":[{"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/formidableengineeringconsultants.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}