{"id":423,"date":"2009-08-19T09:08:36","date_gmt":"2009-08-19T14:08:36","guid":{"rendered":"http:\/\/www.gamescheat.ca\/?p=423"},"modified":"2019-09-04T19:57:40","modified_gmt":"2019-09-05T00:57:40","slug":"explanation-of-standard-input-output-in-unix-and-linux","status":"publish","type":"post","link":"http:\/\/www.gamescheat.ca\/?p=423","title":{"rendered":"Explanation of Standard input-output in Unix and Linux"},"content":{"rendered":"<p>Once a command is run, a process is created. This process then opens three flows: <\/p>\n<p>stdin, called the standard input, where the process will read the input data. By default stdin refers to the keyboard; STDIN is identified by the number 0; <\/p>\n<p>stdout, called standard output, where the process will write the output data. By default, stdin refers to the screen; STDOUT is identified by the number 1; <\/p>\n<p>stderr, called standard error, where the process will write error messages. By default, stderr refers to the screen. STDERR is identified by the number 2; <\/p>\n<p>By default, whenever a program is run data is read from the keyboard and the program sends its output and errors to the screen. However, it is also possible to read data from any input device, even a file, and send the output to a display device, a file, etc. <\/p>\n<div style=\"float: left;\"><div style=\"margin: 15px 15px 15px 15px\";><script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"pub-3319935785736004\";\ngoogle_alternate_color = \"FFFFFF\";\ngoogle_ad_width = 300;\ngoogle_ad_height = 250;\ngoogle_ad_format = \"300x250_as\";\ngoogle_ad_type = \"text_image\";\ngoogle_ad_channel =\"\";\ngoogle_color_border = \"cccccc\";\ngoogle_color_link = \"cc0000\";\ngoogle_color_bg = \"ffffff\";\ngoogle_color_text = \"000000\";\ngoogle_color_url = \"008000\";\n\/\/--><\/script>\n<script type=\"text\/javascript\"\n  src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><\/div><\/div><p>Here is an example for error redirection.<\/p>\n<p>This is a very popular feature that many Unix users are happy to learn. In case you have worked with Unix for some time, you must have realised that for a lot of commands you type you get a lot of error messages. And you are not really bothered about those error messages. For example whenever I perform a search for a file, I always get a lot of permission denied error messages. There may be ways to fix those things. But the simplest way is to redirect the error messages elsewhere so that it doesn\u2019t bother me. In my case I know that errors I get while searching for files would be of no use to me.<\/p>\n<p>Here is a way to redirect the error messages <\/p>\n<p>$ myprogram 2>errorsfile<\/p>\n<p>This above command would execute a program named \u2018 myprogram \u2018 and whatever errors are generated while executing that program would all be added to a file named \u2018 errorsfile \u2018 rather than be displayed on the screen. Remember that 2 is the error output file descriptor. Thus \u2018 2> \u2018 means redirect the error output. <\/p>\n<p>$ myprogram 2>>all_errors_till_now<\/p>\n<p>The above command would be useful in case you have been saving all the error messages for some later use. This time the error messages would append to the file rather than create a new file.<\/p>\n<p>You might realize that in the above case since I wasn\u2019t interested in the error messages generated by the program I redirected the output to a file. But since those error messages don\u2019t interest me I would have to go and delete that file created every time I run that command. Else I would have several such files created all over whenever I redirect my unwanted error output. An excellent way around is shown below<br \/>\n$ find \/ -name s*.jpg 2>\/dev\/null<\/p>\n<p>What\u2019s \/dev\/null ????? That something like a black hole. Whatever is sent to the \u2018 \/dev\/null \u2018 never returns. Neither does one know where it goes. It simple disappears. Isn\u2019t that fantastic !! So remember.. whenever you want to remove something.. something that you don\u2019t want \u2026you could just send it to \/dev\/null.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once a command is run, a process is created. This process then opens three flows: stdin, called the standard input, where the process will read the input data. By default stdin refers to the keyboard; STDIN is identified by the&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.gamescheat.ca\/?p=423\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[55,35],"_links":{"self":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/423"}],"collection":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=423"}],"version-history":[{"count":4,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/423\/revisions"}],"predecessor-version":[{"id":992,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/423\/revisions\/992"}],"wp:attachment":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=423"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}