<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7296660181962989406</id><updated>2011-11-28T07:32:21.228+05:30</updated><category term='C++'/><category term='rsh'/><category term='attachment'/><category term='shell script'/><category term='sun studio'/><category term='new feature'/><category term='stdin'/><category term='map'/><category term='uniq'/><category term='mail client'/><category term='diff'/><category term='multimap'/><category term='sort'/><title type='text'>Sahaj Techstyle</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sahajtechstyle.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sahajtechstyle.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Rahul Upakare</name><uri>http://www.blogger.com/profile/01899365731187368347</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://3.bp.blogspot.com/_9GFq7ZbJTz0/SmCjOCJgAHI/AAAAAAAAKRI/jmYWaJ5fty0/S220/sahaj.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7296660181962989406.post-4979058139723993813</id><published>2008-04-23T00:23:00.010+05:30</published><updated>2008-04-23T01:51:53.748+05:30</updated><title type='text'>Private constructor</title><content type='html'>&lt;b&gt;Colleague&lt;/b&gt;: Hey man, is it allowed to declare a private constructor (and no other public constructors)?&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: (immediately) Yes!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Colleague&lt;/b&gt;: Why would one do that?&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: To disallow other classes to instantiate that class&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Colleague&lt;/b&gt;: But is that class good for anything if other classes cannot instantiate it?&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: Yeah, even if it is a private constructor you can instantiate that class within that class (i.e. inside its own method(s)) and other classes would use that method to access the instance of that class.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Colleague&lt;/b&gt;: But, then I don't see any use of making it private then.&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: When you make things private from rest of the world, you basically want to restrict/control the access of those private things. That is what you can achieve it here too. In this case, you want to control instantiation of the class.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: For example, how can you make sure that class can be instantiated only once?&lt;br /&gt;&lt;b&gt;Colleague&lt;/b&gt;: Ummmm... (thinking for a while). I can declare a variable, let say &lt;i&gt;count&lt;/i&gt; inside a class and will track object instances using that. So if count is 1, I won't allow any new object instantiation of that class.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: But, that &lt;i&gt;count&lt;/i&gt; variable (assuming he is referring to object variable) will be zero (or whatever set to default) for every new instance of that class so, how that will help you?&lt;br /&gt;&lt;b&gt;Colleague&lt;/b&gt;: No, no. It will be a static variable (class variable) and all object instances will share that.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;me&lt;/b&gt;: Ya, you can track object instances using static variable. But for sharing that single instance of class at other places in your application, you either need to declare it globally or declare it as a static variable inside that class only. The later is good, because once you do that you probably don't need that static &lt;i&gt;count&lt;/i&gt; variable. Ya, you don't need. Because you can always check if that instance is not null and that means it is already instantiated. So, return that instance only. Man, what we are discussing is nothing but a singleton pattern only. &lt;br /&gt;&lt;br /&gt;So in Java, it will be like,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class MyClass {&lt;br /&gt;  private static MyClass myClassUniqueInstance;&lt;br /&gt;&lt;br /&gt;  private MyClass() { }&lt;br /&gt;&lt;br /&gt;  public static synchronized MyClass getInstance() {&lt;br /&gt;     if (myClassUniqueInstance == null) {&lt;br /&gt;             myClassUniqueInstance = new MyClass();&lt;br /&gt;     }&lt;br /&gt;     return myClassUniqueInstance;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;synchronized&lt;/i&gt; keyword is added in &lt;i&gt;getInstance()&lt;/i&gt; method to make it thread safe. &lt;br /&gt;&lt;br /&gt;Okay, so trouble for posting this conversation on blog: To let you,&lt;br /&gt;1. ask these kind of questions to yourself and/or others (may be good for interviewer)&lt;br /&gt;2. answer these kind of questions (good for interviewee)&lt;br /&gt;3. know at least one design pattern i.e. "The singleton pattern".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7296660181962989406-4979058139723993813?l=sahajtechstyle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sahajtechstyle.blogspot.com/feeds/4979058139723993813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7296660181962989406&amp;postID=4979058139723993813' title='42 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/4979058139723993813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/4979058139723993813'/><link rel='alternate' type='text/html' href='http://sahajtechstyle.blogspot.com/2008/04/private-constructor.html' title='Private constructor'/><author><name>Rahul Upakare</name><uri>http://www.blogger.com/profile/01899365731187368347</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://3.bp.blogspot.com/_9GFq7ZbJTz0/SmCjOCJgAHI/AAAAAAAAKRI/jmYWaJ5fty0/S220/sahaj.jpg'/></author><thr:total>42</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7296660181962989406.post-8076605151389368774</id><published>2007-11-29T16:34:00.000+05:30</published><updated>2007-11-30T19:47:49.858+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='mail client'/><category scheme='http://www.blogger.com/atom/ns#' term='new feature'/><category scheme='http://www.blogger.com/atom/ns#' term='attachment'/><title type='text'>Can your mail client prompt you, if you forgot to attach a file?</title><content type='html'>How many times you have received any mail which says that there is a file attached, but there isn't any file attached. The sender has actually forgot to attach a file. Also, how many times you have sent such a mail?&lt;br /&gt;&lt;br /&gt;Ya, things like this happens. So what could be the solution? Can we have a mail client intelligent enough to prompt us about missing attachment? Is this possible?&lt;br /&gt;&lt;br /&gt;Looking at the problem, I can see a very simple solution. It goes like this:&lt;br /&gt;&lt;br /&gt;Prompt user before sending a mail WHEN &lt;br /&gt;the mail content HAS WORD like 'attached' or 'enclosed' &lt;br /&gt;AND &lt;br /&gt;there is NO attachment attached&lt;br /&gt;&lt;br /&gt;Also, this check can only be performed, when user wants his mail client to prompt about missing attachment, by explicitly setting the related option in mail client preferences. &lt;br /&gt;&lt;br /&gt;Looking at the mails I have received without attachments, and sometimes the delay caused because of that, I strongly feel that having such a feature will be really useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7296660181962989406-8076605151389368774?l=sahajtechstyle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sahajtechstyle.blogspot.com/feeds/8076605151389368774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7296660181962989406&amp;postID=8076605151389368774' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/8076605151389368774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/8076605151389368774'/><link rel='alternate' type='text/html' href='http://sahajtechstyle.blogspot.com/2007/11/can-your-mail-client-prompt-you-if-you.html' title='Can your mail client prompt you, if you forgot to attach a file?'/><author><name>Rahul Upakare</name><uri>http://www.blogger.com/profile/01899365731187368347</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://3.bp.blogspot.com/_9GFq7ZbJTz0/SmCjOCJgAHI/AAAAAAAAKRI/jmYWaJ5fty0/S220/sahaj.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7296660181962989406.post-8872268488696913733</id><published>2007-11-12T19:14:00.000+05:30</published><updated>2007-11-14T13:02:50.565+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='multimap'/><category scheme='http://www.blogger.com/atom/ns#' term='map'/><category scheme='http://www.blogger.com/atom/ns#' term='sun studio'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>What's wrong with Sun Studio C++?</title><content type='html'>Don't be surprised if you are using multimap and your code is working on other standard C++ compilers and not on Sun Studio C++. e.g. See below code, which is correct according to C++ standards, but it will not compile on Sun Studio C++.&lt;br /&gt;&lt;br /&gt;And if you use map instead of multimap it will work. But hey, you want to use multimap and not map, so what's wrong with Sun Studio C++?&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &amp;lt;map&amp;gt;&lt;br /&gt;#include &amp;lt;utility&amp;gt;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;        std::map&amp;lt;int, int&amp;gt; mymap;&lt;br /&gt;        mymap.insert(std::make_pair(2, 4));&lt;br /&gt;&lt;br /&gt;        std::multimap&amp;lt;int, int&amp;gt; mymultimap;&lt;br /&gt;        mymultimap.insert(std::make_pair(2, 4));&lt;br /&gt;&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If you compile this code with Sun Studio (my version was forte v10.0p1), you probably will get error something like,&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Error: Could not find a match for std::multimap&amp;lt;int, int, std::less&amp;lt;int&amp;gt;, std::allocator&amp;lt;std::pair&amp;lt;const int, int&amp;gt;&amp;gt;&amp;gt;::insert(std::pair&amp;lt;int, int&amp;gt;) needed in main().&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The same code will compile perfectly fine with other standard C++ compilers. So, what's wrong with Sun Studio C++? Is something missing in Sun Studio? &lt;br /&gt;&lt;br /&gt;OK, So to investigate it further, if you open &amp;lt;sun-studio-installation-directory&amp;gt;/prod/include/CC/Cstd/utility, you'll find&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#ifndef _RWSTD_NO_MEMBER_TEMPLATES&lt;br /&gt;    template &amp;lt;class U, class V&amp;gt; pair(const pair&amp;lt;U,V&amp;gt;&amp; p)&lt;br /&gt;      : first(p.first), second(p.second)&lt;br /&gt;    { ; }&lt;br /&gt;#endif&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;and in &amp;lt;sun-studio-installation-directory&amp;gt;/prod/include/CC/Cstd/stdcomp.h, you'll find&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#      define _RWSTD_NO_MEMBER_TEMPLATES             1&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Since _RWSTD_NO_MEMBER_TEMPLATES is defined, member template copy constructor is not available. In case of map class it has function&lt;br /&gt;&lt;code&gt;&lt;br /&gt; pair&amp;lt;iterator, bool&amp;gt; insert (const pair&amp;lt;key_type, mapped_type&amp;gt; &amp;__x)&lt;br /&gt;    {&lt;br /&gt;      return insert (pair&amp;lt;const key_type, mapped_type&amp;gt; (__x.first, __x.second));&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;therefore it works for map class.&lt;br /&gt;&lt;br /&gt;In case of multimap, value_type is pair&amp;lt;const Key, T&amp;gt;, and since pair class lacks the templated copy constructor, insert can't convert pair&amp;lt;int, int&amp;gt; to pair&amp;lt;const int, int&amp;gt;, So we can use following work around:&lt;br /&gt;1.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &amp;lt;map&amp;gt;&lt;br /&gt;#include &amp;lt;utility&amp;gt;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;        std::map&amp;lt;int, int&amp;gt; mymap;&lt;br /&gt;        mymap.insert(std::make_pair(2, 4));&lt;br /&gt;&lt;br /&gt;        std::multimap&amp;lt;int, int&amp;gt; mymultimap;&lt;br /&gt;        mymultimap.insert(std::pair&amp;lt;const int, int&amp;gt;(2, 4));&lt;br /&gt;&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &amp;lt;map&amp;gt;&lt;br /&gt;#include &amp;lt;utility&amp;gt;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;        std::map&amp;lt;int, int&amp;gt; mymap;&lt;br /&gt;        mymap.insert(std::make_pair(2, 4));&lt;br /&gt;&lt;br /&gt;        typedef std::multimap&amp;lt;int, int&amp;gt; intmultimap;&lt;br /&gt;        intmultimap mymultimap;&lt;br /&gt;&lt;br /&gt;        mymultimap.insert(intmultimap::value_type(2,4));&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;3.&lt;br /&gt;If you don't want to change your existing code, you can use more standard-conforming library, by specifying option -library=stlport4, while compiling and linking.&lt;br /&gt;&lt;br /&gt;Sun C++ FAQs indicates that they cannot update the standard library without breaking source and binary compatibility, so they will continue to ship a libCstd with the same limitations. I hope these workarounds will help you then.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7296660181962989406-8872268488696913733?l=sahajtechstyle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sahajtechstyle.blogspot.com/feeds/8872268488696913733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7296660181962989406&amp;postID=8872268488696913733' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/8872268488696913733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/8872268488696913733'/><link rel='alternate' type='text/html' href='http://sahajtechstyle.blogspot.com/2007/11/whats-wrong-with-sun-studio-c.html' title='What&apos;s wrong with Sun Studio C++?'/><author><name>Rahul Upakare</name><uri>http://www.blogger.com/profile/01899365731187368347</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://3.bp.blogspot.com/_9GFq7ZbJTz0/SmCjOCJgAHI/AAAAAAAAKRI/jmYWaJ5fty0/S220/sahaj.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7296660181962989406.post-5436657830292518020</id><published>2007-08-13T10:36:00.000+05:30</published><updated>2007-08-13T22:33:13.515+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='uniq'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='sort'/><category scheme='http://www.blogger.com/atom/ns#' term='diff'/><title type='text'>diffing files in different way</title><content type='html'>The diff utility compares the content of file1 and file2 and writes to standard output a list of changes necessary to convert file1 into file2. diff may not be used when you want to find out which lines in file1 are not present in file2 and vice-a-versa. &lt;br /&gt;&lt;br /&gt;Let's say you have a expected result's output file and a current result's output file,&lt;br /&gt;&lt;br /&gt;expected-output.txt:&lt;br /&gt;12 something some blah              &lt;br /&gt;15 ok ok and not ok&lt;br /&gt;14 someone at somewhere&lt;br /&gt;20 and many more such records&lt;br /&gt;&lt;br /&gt;current-output.txt:&lt;br /&gt;15 ok ok and not ok&lt;br /&gt;13 this is not present in expected output&lt;br /&gt;20 and many more such records&lt;br /&gt;&lt;br /&gt;One quick way to do this is using power of Unix piping, sed, sort and uniq commands.&lt;br /&gt;&lt;br /&gt;cat expected-output.txt | sed 's/^/expected-output.txt /g' &gt; mixed.txt&lt;br /&gt;cat current-output.txt  | sed 's/^/current-output.txt /g' &gt;&gt; mixed.txt&lt;br /&gt;sort +1 mixed.txt | uniq -u -f1 | sort&lt;br /&gt;&lt;br /&gt;I would need to test this for files with really large number of records. But, currently I am satisfied with the above solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7296660181962989406-5436657830292518020?l=sahajtechstyle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sahajtechstyle.blogspot.com/feeds/5436657830292518020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7296660181962989406&amp;postID=5436657830292518020' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/5436657830292518020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/5436657830292518020'/><link rel='alternate' type='text/html' href='http://sahajtechstyle.blogspot.com/2007/08/diffing-files-in-different-way.html' title='diffing files in different way'/><author><name>Rahul Upakare</name><uri>http://www.blogger.com/profile/01899365731187368347</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://3.bp.blogspot.com/_9GFq7ZbJTz0/SmCjOCJgAHI/AAAAAAAAKRI/jmYWaJ5fty0/S220/sahaj.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7296660181962989406.post-3042887094956463596</id><published>2007-08-11T14:33:00.000+05:30</published><updated>2007-08-12T23:27:41.515+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='stdin'/><category scheme='http://www.blogger.com/atom/ns#' term='rsh'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><title type='text'>Don't take my stdin Mr. rsh</title><content type='html'>My colleague came to me and said "I have a script which reads a file line by line and doing some processing for each line, but strangely it is processing only the first line and exiting after that". I said "OK, I guess there must be something in your processing part that is eating all your stdin or a exit command for some condition. Let me see your script".&lt;br /&gt;&lt;br /&gt;Just to give you an idea his script was something like this,&lt;br /&gt;&lt;code&gt;&lt;br /&gt;while read line&lt;br /&gt;do&lt;br /&gt;&amp;nbsp; &amp;nbsp;# blah blah&lt;br /&gt;&amp;nbsp; &amp;nbsp;rsh &amp;lt;remote_server_name&amp;gt; ls /home/someone/something.txt&lt;br /&gt;&amp;nbsp; &amp;nbsp;# blah blah&lt;br /&gt;done &amp;lt; input.txt&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;While I was looking at his script he said "When I comment this part, it processes all the lines and when I uncomment then it processes only the first line." OK, so what's there in that commented part. Bingo!, there is a rsh command. So, rsh seems to be a culprit.&lt;br /&gt;&lt;br /&gt;After reading more about rsh, I found that rsh command cannot tell whether the remote program that it is going to run, need to read from stdin or not. Therefore, rsh copies stdin across the network to the remote program     by absorbing ALL of the input (i.e. till EOF to know when to stop).&lt;br /&gt;&lt;br /&gt;"OK, so you would need to store your stdin (which is mapped to input.txt) before executing rsh and restore it after that. Let us try something like this.", I said.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;exec 4&amp;lt;&amp;amp;0 &lt;br /&gt;while read line &lt;br /&gt;do     &lt;br /&gt;&amp;nbsp; &amp;nbsp;# blah blah     &lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 5&amp;lt;&amp;amp;0     &lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 0&amp;lt;&amp;amp;4     &lt;br /&gt;&amp;nbsp; &amp;nbsp;rsh &amp;lt;remote_server_name&amp;gt; ls /home/someone/something.txt&lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 4&amp;lt;&amp;amp;0     &lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 0&amp;lt;&amp;amp;5      &lt;br /&gt;&amp;nbsp; &amp;nbsp;# blah blah &lt;br /&gt;done &amp;lt; input.txt&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Somehow it didn't work. I am not sure why it didn't work. May be I would need to update this post once I find its reason. Then, I thought why don't we map /dev/null as stdin and let Mr. rsh eat that, and bingo! it worked.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;exec 4&amp;lt;/dev/null  &lt;br /&gt;while read line &lt;br /&gt;do     &lt;br /&gt;&amp;nbsp; &amp;nbsp;# blah blah     &lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 5&amp;lt;&amp;0     &lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 0&amp;lt;&amp;amp;4     &lt;br /&gt;&amp;nbsp; &amp;nbsp;rsh &amp;lt;remote_server_name&amp;gt; ls /home/someone/something.txt     &lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 4&amp;lt;/dev/null&lt;br /&gt;&amp;nbsp; &amp;nbsp;exec 0&amp;lt;&amp;amp;5&lt;br /&gt;&amp;nbsp; &amp;nbsp;# blah blah     &lt;br /&gt;done &amp;lt; input.txt&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;My colleague was happy, because he got one more thing to mention in his weekly report :). I was happy too, for successfully helping and especially for learning something new by the process of that.&lt;br /&gt;&lt;br /&gt;We should always help others, there is no better way to learn than that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7296660181962989406-3042887094956463596?l=sahajtechstyle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sahajtechstyle.blogspot.com/feeds/3042887094956463596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7296660181962989406&amp;postID=3042887094956463596' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/3042887094956463596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7296660181962989406/posts/default/3042887094956463596'/><link rel='alternate' type='text/html' href='http://sahajtechstyle.blogspot.com/2007/08/dont-take-my-stdin-mr-rsh.html' title='Don&apos;t take my stdin Mr. rsh'/><author><name>Rahul Upakare</name><uri>http://www.blogger.com/profile/01899365731187368347</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://3.bp.blogspot.com/_9GFq7ZbJTz0/SmCjOCJgAHI/AAAAAAAAKRI/jmYWaJ5fty0/S220/sahaj.jpg'/></author><thr:total>3</thr:total></entry></feed>
