{"id":66,"date":"2009-02-05T20:57:01","date_gmt":"2009-02-05T20:57:01","guid":{"rendered":"http:\/\/blog.danplanet.com\/wordpress\/?p=66"},"modified":"2009-02-05T20:57:01","modified_gmt":"2009-02-05T20:57:01","slug":"running-strerror-from-the-shell","status":"publish","type":"post","link":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/","title":{"rendered":"Running strerror() from the shell"},"content":{"rendered":"<p>Reasonably often, I have a need to convert an errno variable to its string error message right at the shell.\u00a0 This seems to come up relatively often in kernel development, but occasionally elsewhere.\u00a0 Where I can, I usually just go for a <font face=\"courier new,courier\">printf(&#8220;Error: %mn&#8221<img decoding=\"async\" src=\"https:\/\/www.danplanet.com\/blog\/wp-content\/themes\/wordpress-grey-opaque-master\/images\/smilies\/icon_wink.gif\" alt=\"Smilie: ;)\" title=\"Smilie: ;)\" \/><\/font> or <font face=\"courier new,courier\">printf(&#8220;Error: %sn&#8221;, strerror(foo))<\/font> directly in the debug statement I&#8217;m adding.\u00a0 However, <font face=\"courier new,courier\">%m<\/font> doesn&#8217;t work in the kernel and occasionally I either want or have to avoid recompiling something that just prints the integer value.\u00a0 Chasing the header file chain to figure out what a given error code is can be time consuming and silly, but I&#8217;ve done it.<\/p>\n<p>Recently, I&#8217;ve been trying to notice when I do stupid things repetitively and take the time to write a helper script or shell alias to prevent wasting effort the next time I need to do a particular task.\u00a0 I have a collection of shell aliases, but I also keep a <font face=\"courier new,courier\">~\/bin<\/font> directory with helper scripts for things that fit that mold better.\u00a0 To solve my errno issue, I wrote the following today and stored it in <font face=\"courier new,courier\">~\/bin\/perror<\/font>:<\/p>\n<blockquote>\n<p><font face=\"courier new,courier\">#!\/usr\/bin\/python<\/p>\n<p>import os<br \/>import sys<\/p>\n<p>for i in sys.argv[1:]:<br \/>\u00a0\u00a0\u00a0 i = abs(int(i))<\/p>\n<p>\u00a0\u00a0\u00a0 print &#8220;%3i: %s&#8221; % (i, os.strerror(i))<br \/><\/font><\/p>\n<\/blockquote>\n<p>It could probably be done smaller in a shell alias that calls perl or something, but oh well.\u00a0 This is pretty handy so I can quickly get a couple of values:<\/p>\n<blockquote>\n<p><font face=\"courier new,courier\">% perror 111 22<br \/>111: Connection refused<br \/>\u00a022: Invalid argument<\/font><\/p>\n<\/blockquote>\n<p>I&#8217;ve already used it several times today, so it was definitely worth the 2 minutes it took to codify it. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reasonably often, I have a need to convert an errno variable to its string error message right at the shell.\u00a0 This seems to come up relatively often in kernel development, but occasionally elsewhere.\u00a0 Where I can, I usually just go &hellip; <a href=\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-codemonkeying"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Running strerror() from the shell - Right Angles<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running strerror() from the shell - Right Angles\" \/>\n<meta property=\"og:description\" content=\"Reasonably often, I have a need to convert an errno variable to its string error message right at the shell.\u00a0 This seems to come up relatively often in kernel development, but occasionally elsewhere.\u00a0 Where I can, I usually just go &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\" \/>\n<meta property=\"og:site_name\" content=\"Right Angles\" \/>\n<meta property=\"article:published_time\" content=\"2009-02-05T20:57:01+00:00\" \/>\n<meta name=\"author\" content=\"Dan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\"},\"author\":{\"name\":\"Dan\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"headline\":\"Running strerror() from the shell\",\"datePublished\":\"2009-02-05T20:57:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\"},\"wordCount\":271,\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"articleSection\":[\"Codemonkeying\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\",\"url\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\",\"name\":\"Running strerror() from the shell - Right Angles\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\"},\"datePublished\":\"2009-02-05T20:57:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.danplanet.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running strerror() from the shell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\",\"url\":\"https:\/\/www.danplanet.com\/blog\/\",\"name\":\"Right Angles\",\"description\":\"If they&#039;re not right...they&#039;re wrong\",\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\",\"name\":\"Dan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"caption\":\"Dan\"},\"logo\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.danplanet.com\/blog\/author\/dan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running strerror() from the shell - Right Angles","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/","og_locale":"en_US","og_type":"article","og_title":"Running strerror() from the shell - Right Angles","og_description":"Reasonably often, I have a need to convert an errno variable to its string error message right at the shell.\u00a0 This seems to come up relatively often in kernel development, but occasionally elsewhere.\u00a0 Where I can, I usually just go &hellip; Continue reading &rarr;","og_url":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/","og_site_name":"Right Angles","article_published_time":"2009-02-05T20:57:01+00:00","author":"Dan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dan","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/#article","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/"},"author":{"name":"Dan","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"headline":"Running strerror() from the shell","datePublished":"2009-02-05T20:57:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/"},"wordCount":271,"publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"articleSection":["Codemonkeying"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/","url":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/","name":"Running strerror() from the shell - Right Angles","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/#website"},"datePublished":"2009-02-05T20:57:01+00:00","breadcrumb":{"@id":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.danplanet.com\/blog\/2009\/02\/05\/running-strerror-from-the-shell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.danplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Running strerror() from the shell"}]},{"@type":"WebSite","@id":"https:\/\/www.danplanet.com\/blog\/#website","url":"https:\/\/www.danplanet.com\/blog\/","name":"Right Angles","description":"If they&#039;re not right...they&#039;re wrong","publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c","name":"Dan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","caption":"Dan"},"logo":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.danplanet.com\/blog\/author\/dan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":0,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}