Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Handmade Character Soft Toy Bluey Bingo
anil1961
Updated:
Aug 3, 2026
Colombo
Dahua POE Switch 8 Ports (DH-PFS3010-8ET-65)
hashaz2012
Updated:
Aug 3, 2026
Ad icon
Singapore V2Ray VPN for Tunneling
hu KANNA
Updated:
Jul 31, 2026
Dating Website & Online Chat Room
hotvideo
Updated:
Jul 30, 2026
DJI Mini 4 Pro Drone Combo Plus
Hawaka
Updated:
Jul 30, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
DevOps_UNIX / Linux_8_I/O_රිඩිරෙක්ෂන්_සහ_Piping.
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="ja2k17ja" data-source="post: 21849839" data-attributes="member: 562617"><p><span style="font-size: 15px"><strong><u>3) Standard Error Redirection</u></strong></span></p><p><span style="font-size: 15px">අපි මේ ගැන කතා කරන්න කලින් බලමු මොනවද මේ "Error" කියල කියන්නෙ. මට එක ඔයාට පොඩි උදාහරනයක් මගින් පෙන්නලා දෙන්න පුළුවන් එතකොට කටින් කියනවට වැඩ හොදට තේරුම් ගන්න පුළුවන්. <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මුලින්ම අපේ හෝම් ඩිරෙක්ටරිය ඇතුලෙ my_errors කියල අලුතින් ඩිරෙක්ටරියක් හදා ගනිමු. මෙන්න මේ වගේ </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>mkdir ~/my_errors</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් <strong>cd ~/my_errors</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපි මෙන්න මේ කමාන්ඩ් එක දීල අපි හදපු "my_errors" ඩිරෙක්ටරි එක ඇතුලෙ "windows" කියල file එකක විස්තර ls -l මගින් ගන්න බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l windows</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">හ්ම් .. අපිට් මෙන්න මෙහෙම දෙයක් "ls: cannot access 'windows': No such file or directory" ලැබුන. අපි මෙන්න මේකට කියන්නෙ "<strong>execution error</strong>" එකක් කියල. අපි දැන් බලමු කොහොමද මේ execution error එක අපි දකින්නේ කියල. මේ Error එක ඇතිවුනේ ls ඇතුලෙ මම කලින් කියපු විදියට standard error file (stderr) එක මගින් terminal screen එකට ඇවිල්ල තමයි අපිට display වෙන්නෙ. මම ඔයාලට කියල දුන්න UNIX / Linux වල stderr එක පෙරනිමි ලෙස (By default) terminal screen එකට සම්බන්ද වෙලා තියෙනව කියල. අන්න ඒ නිසා තමයි අපිට Error එක terminal screen එකේ පෙනුනෙ. </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි "Standard Error Redirection" වලදී සිදු කරනේ ඉහලින් විස්තර කරපු Error එක terminal screen එක වෙතට යොමු නොකර file එකකට යොමු කිරීමයි. හොදින් මතක තියාගන්න අපිට් stderr එක file එකකට පමණක් නොවේ stdout වෙතටත් redirect කරන්න පුළුවන් බව. මම එය කරන විදියත් ඔයාලට පසුව කියල දෙන්නම්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මුලින්ම file එකකට redirect කරන ආකාරය ඉගෙන ගනිමු අපි මේ සදහා යොදා ගනුයේ "<strong><span style="color: Red">2></span></strong>".</span></p><p><span style="font-size: 15px">අපිට Input Redirection සහ Output Redirection සදහා ක්රම දෙකක් තිබුනද "Standard Error Redirection" සදහා ඇත්තේ file descriptor එක බාවිතා කරන සිදු කරන මෙම ක්රමය "<span style="color: red">2></span>" පමණි.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් බලමු "ls: cannot access 'windows': No such file or directory" කියන error එක file එකකට redirect කරන ආකාරය.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l windows 2> this_is_my_error.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැක්ක නේද අපිට මේපාර "ls: cannot access 'windows': No such file or directory" කියල එකක් දැකගන්න ලැබුනේ නෑ. අපි දැන් බලමු "this_is_my_error.txt" file එක ඇතුලෙ මොනවද තියෙන්නෙ කියල .</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < this_is_my_error.txt</strong> හෝ <strong>cat this_is_my_error.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">හරි දැන් ඔය කියපු error එක අපේ "this_is_my_error.txt" file එක ඇතුලෙ ලියවිලා තියෙන්නෙ.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මෙන්න මේකත් කරලා බලන්න.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් ඔයාලට තේරුම් ගන්න පුළුවන් "<strong><span style="color: red">2>></span></strong>" එකෙන් වෙන වැඩෙත්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>මේ කරුණත් මතක තියාගන්න අපි "2>" කරන සැම විටම standard error එකක් තිබුනත් නැතත් අලුතින් file එකක් සැදෙනවා. error එකක් නැතිවිට හිස් file එකක් සැදෙනවා.</strong></span></p><p><span style="font-size: 15px"><strong></strong></span></p><p><span style="font-size: 15px">අපිට එය මෙසේ ටෙස්ට් කරල බලන්න පුළුවන්. අපි "windows" කියල file එකක් හදමු .</span></p><p><span style="font-size: 15px">ට්රයි <strong>touch windows</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් <strong>ls -l windows</strong> දීල බලමු </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් "<strong>this_is_my_new_error.txt</strong>" කියන file එකට stderr එක redirect කරමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැනට අපි සතුව "this_is_my_new_error.txt" කියල file එකක් නෑ . මේ බලන්න </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපි "<strong>ls -l windows 2> this_is_my_new_error.txt</strong>" කමාන්ඩ් එක දෙමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l windows <span style="color: red">2></span> this_is_my_new_error.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මෙහිදී windows නමින් file එකක් තිබුන නිසා error එකක් ඇතිවුනේ නෑ. දැන් බලමු "this_is_my_new_error.txt" කියල file එකක් හැදිල තියෙනවද කියල </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l this_is_my_new_error.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මේ බලන්න මම කියපු විදියට "this_is_my_new_error.txt" කියල file එකක් හැදිල තියෙනව.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් බලමු "<span style="color: Blue">this_is_my_new_error.txt</span>" එක ඇතුලේ මොනවද තියෙන්නේ කියල .</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < this_is_my_new_error.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">නමුත් file එක ඇතුලෙ කිසිම දෙයක් නෑ. දැන් ඔයාලට මම කියපු දේ හොදට පැහැදිලියි.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් මම ඔයාලට කියල දෙන්නම් <strong>stderr</strong> එක stdout එකට redirect කරන විදිය.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මුලින්ම මෙන්න මේ කමාන්ඩ් එක දිහා බලමු "<strong>ls -l lindows > this_is_my_out</strong>" මේකෙන් කියන්නෙ "lindows" කියල file එකක් අපේ current directory යෙ තිබුනොත් ඒකෙ විස්තර stdout එක redirect වීමෙන් <strong>this_is_my_out</strong> කියන file එකේ සටහන් වෙනව කියන එකයි.</span></p><p><span style="font-size: 15px">අපි ට්රයි කරලා බලමු.</span></p><p><span style="font-size: 15px">"lindows" කියල file එකක් හදමු </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>stdout</strong> එක "<strong>this_is_my_out</strong>" එකට redirect කරමු</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">"this_is_my_out" කියන file එකේ තියෙන දේ බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ඒ file එක (<span style="color: blue">this_is_my_out</span>) ඇතුලෙ මේ ටික තියෙනව "-rw-r--r-- 1 nix nix 0 Jun 23 16:58 lindows".</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපිට ඕන error එකක් ඇතිකරන්න. අපිට ලෙහෙසියෙන්ම එක කරන්න පුළුවන්. "lindows" කියන file එක delete කිරීමෙන්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">හරි දැන් බලමු කලින් දීපු ls -l lindows > this_is_my_out කමාන්ඩ් එක නැවත දීල .</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l lindows > this_is_my_out</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි හිතපු විදියටම error එකක් ඇතිවුණා ඒ වගේම ඒක terminal screen එකේ පෙන්නුවා. අපි බලමු මොනවද දැන් "this_is_my_out" කියන file එකේ තියෙන්නෙ කියල.</span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < this_is_my_out</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>"this_is_my_out" එක හිස් file එකක්.</strong></span></p><p><span style="font-size: 15px">ඔන්න දැන් මම කියල දෙන්නම් කොහොමද අපි "ls: cannot access 'lindows': No such file or directory" කියන error එක මෙන්න මේ "this_is_my_out" කියන file එකට stdout එක (>) මගින් යොමුකරන්නෙ කියල.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l lindows > this_is_my_out <span style="color: Red">2>&1</span></strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් ට්රයි <strong>cat < this_is_my_out</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැක්ක නේද වෙලා තියෙන දේ. දැන් ls: cannot access 'lindows': No such file or directory කියන error එක stdout redirection එක මගින් file එකකට redirect වෙලා තියෙන්නෙ .</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>command <span style="color: Magenta">--></span> stderr<span style="color: magenta"> --></span> stdout <span style="color: magenta">--></span> this_is_my_out</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපි නැවතත් "lindows" කියන file එක හදමු. </span></p><p><span style="font-size: 15px">ට්රයි <strong>touch lindows</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් බලමු "lindows" කියන file එක ඇතිවිට මේ <strong>ls -l lindows > this_is_my_out <span style="color: red">2>&1</span></strong> කමාන්ඩ් එකෙන් වෙනදේ.</span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l lindows > this_is_my_out 2>&1</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් ට්රයි <strong>cat < this_is_my_out</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>අපිට මෙම ක්රමයෙන් stdout හා stderr කියන දෙකම එක file එකකට redirect කරන්න පුළුවන් කියල ඔයාලට වැටහෙනව. shell scripts වලදී අපිට මේවගේ දේවල් හුගක් උපකාරී වෙනව.</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි බලමු මම අලුතින් එකතු කරපු මෙන්න මේ " <span style="color: red"><strong>2>&1</strong></span>" කොටස ගැන.</span></p><p><span style="font-size: 15px">ඔයාල දැන් දන්නවා "2>" කියන්නේ stderr (standard error file) කියල. "<strong>&1</strong>" මගින් file descriptor <span style="color: Blue">1</span> නියෝජනය කරනව. අපි මෙතන කරල තියෙන්නෙ stderr (standard error file) එක file descriptor හි අගය 1 වන standard file ලයට කොපි කිරීමයි. ඒකියන්නෙ stdout කියන standard output file එකට කොපි කිරීමයි.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපිට මෙන්න මේ කාරණාවත් හුගක් වැදගත් වෙනවා. අපි කිසියම් කමාන්ඩ් එකක් රන් කරනකොට එකෙන් ලැබෙන erros ටික terminal screen එකේ display වෙන එක නතර කරගැනීමට. අපිට පුළුවන් <strong>stderr</strong> එක <strong>/dev/null</strong> එකට redirect කරන්න.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l unix_rocks </strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් "<strong>2> /dev/null</strong>" සමග ට්රයි <strong>ls -l unix_rocks 2> /dev/null</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">එවිට "ls: cannot access 'unix_rocks': No such file or directory" කියන error එක /dev/null වලට ගිහිල්ල නැතිවෙනව.</span></p><p><span style="font-size: 15px"><strong>/dev/null</strong> ගැනත් ඉදිරියේදී කතා කරනව.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මම හිතනව දැනට ඔයාලට මේ කරුණු ටික ඉදිරි වැඩ කටයුතු ටික පටන් ගන්න ප්රමාණවත් වේවී කියල. ටිකක් සංකීර්ණ කරුණු කිහිපයක් ඉතිරිවෙලා තියෙනව. නමුත් එක කියල දෙන්න හොදම වෙලාව දැන් නොවේ<img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /> අපි ඊළගට pipe ගැන කතාකරල අද පාඩම අවසන් කරමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong><u>4) pipe</u></strong></span></p><p><span style="font-size: 15px">අපි pipe කියල හදුන්වන්නෙ UNIX / Linux Kernel එක ඇතුලෙ තියෙන <strong>unnamed pipes</strong>. ( මම ඔයාලට Named pipe ගැන පොඩි හැදින් වීමක් DevOps_මුලික_UNIX / Linux_කමන්ඩ්ස් _5 - රිටර්න් ටු ls <a href="http://www.elakiri.com/forum/showthread.php?t=1803283" target="_blank">http://www.elakiri.com/forum/showthread.php?t=1803283</a> ලිපියෙන් කියල දුන්න මතකද? එහිදී මම unnamed pipes ගැනත් වචන කිහිපයක් කතා කළා. මතකද ?)</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් බලමු මොනවද මේ pipe කියන්නෙ කියල. ඔයාලට මතකද මම මේ පාඩමේදී කිව්වා (Output Redirection). <strong>එක කමාන්ඩ් එකක stdout එක තවත් කමාන්ඩ් එකක stdin එකට දෙන්න පුළුවන් කියා</strong>. අපි අන්න ඒ විදියට කරන එකට කියන්නෙ pipe කියල.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">සරලව කියනවා නම් <strong><span style="color: Red">පළමු කමාන්ඩ් එකේ output එක දෙවන කමාන්ඩ් එකේ input එක බවට යොදා ගැනීම</span></strong>. අපි මේ සදහා <span style="color: red"><strong>|</strong></span> කියන pipe operator එක බාවිතා කරනව.</span></p><p><span style="font-size: 15px">මෙය සරල උදාහරනයක් මගින් තේරුම් ගන්න පුළුවන්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ඔයාල දැනටමත් දන්නව මෙන්න මේ "<strong>cat < /etc/passwd</strong>" කමාන්ඩ් එකේ තේරුම මොකක්ද කියල. අපිට් එමගින් /etc/passwd file එකේ අන්තර්ගත දේවල් බලාගන්න පුළුවන්. ඒ මොකද ඒ කමාන්ඩ් එකේ stdout එක terminal screen එකට සම්බන්ද වෙලා තියෙන නිසා.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් මේ stdout එක වෙනත් කමාන්ඩ් එකක input එකක් විදියට යොදා ගනිමු. අපි ඒ සදහා මෙන්න මේ "| " pipe operator එක බාවිතා කරනව .</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < /etc/passwd | wc -l</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>මෙතන අපි කරලා තියෙන්නෙ පළවන කමාන්ඩ් එකේ stdout එක terminal screen එකට් නොදී wc -l කියන කමාන්ඩ් එකට ඉන්පුට් එකක් විදියට pipe එක තුලින් යොමු කිරීමයි</strong>. අන්තිමට wc -l හි stdout එක terminal screen එක හා සම්බන්ද බැවින් අපිට් wc -l හි output එක දැක ගන්න පුළුවන්. </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපිට අපිට අවශ්ෂනම් wc -l හි stdout එකද, තවත් කමාන්ඩ් එකක input එකකට යොමුකරන්න පුළුවන්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < /etc/passwd | wc -l | wc -l</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">** wc -l කමාන්ඩ් එකෙන් අපිට file එකක තිබෙන new line ගණන (\n) ගණන් කර ගැනීමට පුළුවන්. මෙය බොහෝවිට file එකේ තිබෙන text lines ගන්නට සමානයි. ඇතැම් අවස්ථාවලදී අන්තිම line එකේ "\n" අඩංගු නොවුවිට එය ගණනය කිරීමට ඇතුලත් නොවේ. මෙය පැහැදිලි කිරීම පසුවට කල් තබමි <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /> </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ඉදිරියේදී pipe ගැන තවත් උදාහරණ කිහිපක් අනෙක් පාඩම් තුලදී ඔයාලට ඉදිරිපත් කරන්නම්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අවසාන වශයෙන් කියන්න තියෙනෙ UNIX / Linux pipe වලට ඉතා විශාල ප්රමාණයේ data සමග සෙල්ලම් කිරීමට පුළුවන.</span></p><p><span style="font-size: 15px">මම මේ pipe උපයෝගී කරගෙන විදේශීය රුපවාහිනී අයතනයකට HD live streaming 1080p සිස්ටම් එකක් developed කරා. එහිදී SDI Video source එකෙන් එන <strong>1.485 Gbit/s</strong> data ප්රමාණයක් live encoder එකට යොමු කලේ pipe එකකින්. දැන් ඔයාලට හිතාගන්න පුලුවන්නේද UNIX / Linux වල තියෙන පොඩි පොඩි දේවල් අපි හිතනවටවඩා හුගක් බලගතුයි කියල. මේ වගේ දේවල් කරන ආකාරයත් ඔයාලට ඉදිරියේදී කියල දෙන්න තමයි මගේ අදහස.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අද ටිකක් විතර මහන්සියි . මට මේක ඊයේ ඉවරකර ගන්න බැරිවුණා. ගෙදර පොඩි අයගෙ school වැඩ ටිකක් තිබුන. </span></p><p><span style="font-size: 15px">අලුත් පාඩමකින් හමුවෙමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ස්තුතියි!</span></p><p><a href="http://www.elakiri.com/forum/showthread.php?p=21854337#post21854337" target="_blank"><span style="font-size: 15px">DevOps_UNIX / Linux_9_UNIX / Linux Presesses ගැන දැන ගනිමු පළමු කොටස</span></a></p></blockquote><p></p>
[QUOTE="ja2k17ja, post: 21849839, member: 562617"] [SIZE="4"][B][U]3) Standard Error Redirection[/U][/B] අපි මේ ගැන කතා කරන්න කලින් බලමු මොනවද මේ "Error" කියල කියන්නෙ. මට එක ඔයාට පොඩි උදාහරනයක් මගින් පෙන්නලා දෙන්න පුළුවන් එතකොට කටින් කියනවට වැඩ හොදට තේරුම් ගන්න පුළුවන්. :) මුලින්ම අපේ හෝම් ඩිරෙක්ටරිය ඇතුලෙ my_errors කියල අලුතින් ඩිරෙක්ටරියක් හදා ගනිමු. මෙන්න මේ වගේ ට්රයි [B]mkdir ~/my_errors[/B] දැන් [B]cd ~/my_errors[/B] දැන් අපි මෙන්න මේ කමාන්ඩ් එක දීල අපි හදපු "my_errors" ඩිරෙක්ටරි එක ඇතුලෙ "windows" කියල file එකක විස්තර ls -l මගින් ගන්න බලමු. ට්රයි [B]ls -l windows[/B] හ්ම් .. අපිට් මෙන්න මෙහෙම දෙයක් "ls: cannot access 'windows': No such file or directory" ලැබුන. අපි මෙන්න මේකට කියන්නෙ "[B]execution error[/B]" එකක් කියල. අපි දැන් බලමු කොහොමද මේ execution error එක අපි දකින්නේ කියල. මේ Error එක ඇතිවුනේ ls ඇතුලෙ මම කලින් කියපු විදියට standard error file (stderr) එක මගින් terminal screen එකට ඇවිල්ල තමයි අපිට display වෙන්නෙ. මම ඔයාලට කියල දුන්න UNIX / Linux වල stderr එක පෙරනිමි ලෙස (By default) terminal screen එකට සම්බන්ද වෙලා තියෙනව කියල. අන්න ඒ නිසා තමයි අපිට Error එක terminal screen එකේ පෙනුනෙ. අපි "Standard Error Redirection" වලදී සිදු කරනේ ඉහලින් විස්තර කරපු Error එක terminal screen එක වෙතට යොමු නොකර file එකකට යොමු කිරීමයි. හොදින් මතක තියාගන්න අපිට් stderr එක file එකකට පමණක් නොවේ stdout වෙතටත් redirect කරන්න පුළුවන් බව. මම එය කරන විදියත් ඔයාලට පසුව කියල දෙන්නම්. මුලින්ම file එකකට redirect කරන ආකාරය ඉගෙන ගනිමු අපි මේ සදහා යොදා ගනුයේ "[B][COLOR="Red"]2>[/COLOR][/B]". අපිට Input Redirection සහ Output Redirection සදහා ක්රම දෙකක් තිබුනද "Standard Error Redirection" සදහා ඇත්තේ file descriptor එක බාවිතා කරන සිදු කරන මෙම ක්රමය "[COLOR="red"]2>[/COLOR]" පමණි. අපි දැන් බලමු "ls: cannot access 'windows': No such file or directory" කියන error එක file එකකට redirect කරන ආකාරය. ට්රයි [B]ls -l windows 2> this_is_my_error.txt[/B] දැක්ක නේද අපිට මේපාර "ls: cannot access 'windows': No such file or directory" කියල එකක් දැකගන්න ලැබුනේ නෑ. අපි දැන් බලමු "this_is_my_error.txt" file එක ඇතුලෙ මොනවද තියෙන්නෙ කියල . ට්රයි [B]cat < this_is_my_error.txt[/B] හෝ [B]cat this_is_my_error.txt[/B] හරි දැන් ඔය කියපු error එක අපේ "this_is_my_error.txt" file එක ඇතුලෙ ලියවිලා තියෙන්නෙ. මෙන්න මේකත් කරලා බලන්න. දැන් ඔයාලට තේරුම් ගන්න පුළුවන් "[B][COLOR="red"]2>>[/COLOR][/B]" එකෙන් වෙන වැඩෙත්. [B]මේ කරුණත් මතක තියාගන්න අපි "2>" කරන සැම විටම standard error එකක් තිබුනත් නැතත් අලුතින් file එකක් සැදෙනවා. error එකක් නැතිවිට හිස් file එකක් සැදෙනවා. [/B] අපිට එය මෙසේ ටෙස්ට් කරල බලන්න පුළුවන්. අපි "windows" කියල file එකක් හදමු . ට්රයි [B]touch windows[/B] දැන් [B]ls -l windows[/B] දීල බලමු අපි දැන් "[B]this_is_my_new_error.txt[/B]" කියන file එකට stderr එක redirect කරමු. දැනට අපි සතුව "this_is_my_new_error.txt" කියල file එකක් නෑ . මේ බලන්න දැන් අපි "[B]ls -l windows 2> this_is_my_new_error.txt[/B]" කමාන්ඩ් එක දෙමු. ට්රයි [B]ls -l windows [COLOR="red"]2>[/COLOR] this_is_my_new_error.txt[/B] මෙහිදී windows නමින් file එකක් තිබුන නිසා error එකක් ඇතිවුනේ නෑ. දැන් බලමු "this_is_my_new_error.txt" කියල file එකක් හැදිල තියෙනවද කියල ට්රයි [B]ls -l this_is_my_new_error.txt[/B] මේ බලන්න මම කියපු විදියට "this_is_my_new_error.txt" කියල file එකක් හැදිල තියෙනව. දැන් බලමු "[COLOR="Blue"]this_is_my_new_error.txt[/COLOR]" එක ඇතුලේ මොනවද තියෙන්නේ කියල . ට්රයි [B]cat < this_is_my_new_error.txt[/B] නමුත් file එක ඇතුලෙ කිසිම දෙයක් නෑ. දැන් ඔයාලට මම කියපු දේ හොදට පැහැදිලියි. දැන් මම ඔයාලට කියල දෙන්නම් [B]stderr[/B] එක stdout එකට redirect කරන විදිය. මුලින්ම මෙන්න මේ කමාන්ඩ් එක දිහා බලමු "[B]ls -l lindows > this_is_my_out[/B]" මේකෙන් කියන්නෙ "lindows" කියල file එකක් අපේ current directory යෙ තිබුනොත් ඒකෙ විස්තර stdout එක redirect වීමෙන් [B]this_is_my_out[/B] කියන file එකේ සටහන් වෙනව කියන එකයි. අපි ට්රයි කරලා බලමු. "lindows" කියල file එකක් හදමු [B]stdout[/B] එක "[B]this_is_my_out[/B]" එකට redirect කරමු "this_is_my_out" කියන file එකේ තියෙන දේ බලමු. ඒ file එක ([COLOR="blue"]this_is_my_out[/COLOR]) ඇතුලෙ මේ ටික තියෙනව "-rw-r--r-- 1 nix nix 0 Jun 23 16:58 lindows". දැන් අපිට ඕන error එකක් ඇතිකරන්න. අපිට ලෙහෙසියෙන්ම එක කරන්න පුළුවන්. "lindows" කියන file එක delete කිරීමෙන්. හරි දැන් බලමු කලින් දීපු ls -l lindows > this_is_my_out කමාන්ඩ් එක නැවත දීල . ට්රයි [B]ls -l lindows > this_is_my_out[/B] අපි හිතපු විදියටම error එකක් ඇතිවුණා ඒ වගේම ඒක terminal screen එකේ පෙන්නුවා. අපි බලමු මොනවද දැන් "this_is_my_out" කියන file එකේ තියෙන්නෙ කියල. ට්රයි [B]cat < this_is_my_out[/B] [B]"this_is_my_out" එක හිස් file එකක්.[/B] ඔන්න දැන් මම කියල දෙන්නම් කොහොමද අපි "ls: cannot access 'lindows': No such file or directory" කියන error එක මෙන්න මේ "this_is_my_out" කියන file එකට stdout එක (>) මගින් යොමුකරන්නෙ කියල. ට්රයි [B]ls -l lindows > this_is_my_out [COLOR="Red"]2>&1[/COLOR][/B] දැන් ට්රයි [B]cat < this_is_my_out[/B] දැක්ක නේද වෙලා තියෙන දේ. දැන් ls: cannot access 'lindows': No such file or directory කියන error එක stdout redirection එක මගින් file එකකට redirect වෙලා තියෙන්නෙ . [B]command [COLOR="Magenta"]-->[/COLOR] stderr[COLOR="magenta"] -->[/COLOR] stdout [COLOR="magenta"]-->[/COLOR] this_is_my_out[/B] දැන් අපි නැවතත් "lindows" කියන file එක හදමු. ට්රයි [B]touch lindows[/B] දැන් බලමු "lindows" කියන file එක ඇතිවිට මේ [B]ls -l lindows > this_is_my_out [COLOR="red"]2>&1[/COLOR][/B] කමාන්ඩ් එකෙන් වෙනදේ. ට්රයි [B]ls -l lindows > this_is_my_out 2>&1[/B] දැන් ට්රයි [B]cat < this_is_my_out[/B] [B]අපිට මෙම ක්රමයෙන් stdout හා stderr කියන දෙකම එක file එකකට redirect කරන්න පුළුවන් කියල ඔයාලට වැටහෙනව. shell scripts වලදී අපිට මේවගේ දේවල් හුගක් උපකාරී වෙනව.[/B] අපි බලමු මම අලුතින් එකතු කරපු මෙන්න මේ " [COLOR="red"][B]2>&1[/B][/COLOR]" කොටස ගැන. ඔයාල දැන් දන්නවා "2>" කියන්නේ stderr (standard error file) කියල. "[B]&1[/B]" මගින් file descriptor [COLOR="Blue"]1[/COLOR] නියෝජනය කරනව. අපි මෙතන කරල තියෙන්නෙ stderr (standard error file) එක file descriptor හි අගය 1 වන standard file ලයට කොපි කිරීමයි. ඒකියන්නෙ stdout කියන standard output file එකට කොපි කිරීමයි. අපිට මෙන්න මේ කාරණාවත් හුගක් වැදගත් වෙනවා. අපි කිසියම් කමාන්ඩ් එකක් රන් කරනකොට එකෙන් ලැබෙන erros ටික terminal screen එකේ display වෙන එක නතර කරගැනීමට. අපිට පුළුවන් [B]stderr[/B] එක [B]/dev/null[/B] එකට redirect කරන්න. ට්රයි [B]ls -l unix_rocks [/B] දැන් "[B]2> /dev/null[/B]" සමග ට්රයි [B]ls -l unix_rocks 2> /dev/null[/B] එවිට "ls: cannot access 'unix_rocks': No such file or directory" කියන error එක /dev/null වලට ගිහිල්ල නැතිවෙනව. [B]/dev/null[/B] ගැනත් ඉදිරියේදී කතා කරනව. මම හිතනව දැනට ඔයාලට මේ කරුණු ටික ඉදිරි වැඩ කටයුතු ටික පටන් ගන්න ප්රමාණවත් වේවී කියල. ටිකක් සංකීර්ණ කරුණු කිහිපයක් ඉතිරිවෙලා තියෙනව. නමුත් එක කියල දෙන්න හොදම වෙලාව දැන් නොවේ:) අපි ඊළගට pipe ගැන කතාකරල අද පාඩම අවසන් කරමු. [B][U]4) pipe[/U][/B] අපි pipe කියල හදුන්වන්නෙ UNIX / Linux Kernel එක ඇතුලෙ තියෙන [B]unnamed pipes[/B]. ( මම ඔයාලට Named pipe ගැන පොඩි හැදින් වීමක් DevOps_මුලික_UNIX / Linux_කමන්ඩ්ස් _5 - රිටර්න් ටු ls [url]http://www.elakiri.com/forum/showthread.php?t=1803283[/url] ලිපියෙන් කියල දුන්න මතකද? එහිදී මම unnamed pipes ගැනත් වචන කිහිපයක් කතා කළා. මතකද ?) අපි දැන් බලමු මොනවද මේ pipe කියන්නෙ කියල. ඔයාලට මතකද මම මේ පාඩමේදී කිව්වා (Output Redirection). [B]එක කමාන්ඩ් එකක stdout එක තවත් කමාන්ඩ් එකක stdin එකට දෙන්න පුළුවන් කියා[/B]. අපි අන්න ඒ විදියට කරන එකට කියන්නෙ pipe කියල. සරලව කියනවා නම් [B][COLOR="Red"]පළමු කමාන්ඩ් එකේ output එක දෙවන කමාන්ඩ් එකේ input එක බවට යොදා ගැනීම[/COLOR][/B]. අපි මේ සදහා [COLOR="red"][B]|[/B][/COLOR] කියන pipe operator එක බාවිතා කරනව. මෙය සරල උදාහරනයක් මගින් තේරුම් ගන්න පුළුවන්. ඔයාල දැනටමත් දන්නව මෙන්න මේ "[B]cat < /etc/passwd[/B]" කමාන්ඩ් එකේ තේරුම මොකක්ද කියල. අපිට් එමගින් /etc/passwd file එකේ අන්තර්ගත දේවල් බලාගන්න පුළුවන්. ඒ මොකද ඒ කමාන්ඩ් එකේ stdout එක terminal screen එකට සම්බන්ද වෙලා තියෙන නිසා. අපි දැන් මේ stdout එක වෙනත් කමාන්ඩ් එකක input එකක් විදියට යොදා ගනිමු. අපි ඒ සදහා මෙන්න මේ "| " pipe operator එක බාවිතා කරනව . ට්රයි [B]cat < /etc/passwd | wc -l[/B] [B]මෙතන අපි කරලා තියෙන්නෙ පළවන කමාන්ඩ් එකේ stdout එක terminal screen එකට් නොදී wc -l කියන කමාන්ඩ් එකට ඉන්පුට් එකක් විදියට pipe එක තුලින් යොමු කිරීමයි[/B]. අන්තිමට wc -l හි stdout එක terminal screen එක හා සම්බන්ද බැවින් අපිට් wc -l හි output එක දැක ගන්න පුළුවන්. අපිට අපිට අවශ්ෂනම් wc -l හි stdout එකද, තවත් කමාන්ඩ් එකක input එකකට යොමුකරන්න පුළුවන්. ට්රයි [B]cat < /etc/passwd | wc -l | wc -l[/B] ** wc -l කමාන්ඩ් එකෙන් අපිට file එකක තිබෙන new line ගණන (\n) ගණන් කර ගැනීමට පුළුවන්. මෙය බොහෝවිට file එකේ තිබෙන text lines ගන්නට සමානයි. ඇතැම් අවස්ථාවලදී අන්තිම line එකේ "\n" අඩංගු නොවුවිට එය ගණනය කිරීමට ඇතුලත් නොවේ. මෙය පැහැදිලි කිරීම පසුවට කල් තබමි :) ඉදිරියේදී pipe ගැන තවත් උදාහරණ කිහිපක් අනෙක් පාඩම් තුලදී ඔයාලට ඉදිරිපත් කරන්නම්. අවසාන වශයෙන් කියන්න තියෙනෙ UNIX / Linux pipe වලට ඉතා විශාල ප්රමාණයේ data සමග සෙල්ලම් කිරීමට පුළුවන. මම මේ pipe උපයෝගී කරගෙන විදේශීය රුපවාහිනී අයතනයකට HD live streaming 1080p සිස්ටම් එකක් developed කරා. එහිදී SDI Video source එකෙන් එන [B]1.485 Gbit/s[/B] data ප්රමාණයක් live encoder එකට යොමු කලේ pipe එකකින්. දැන් ඔයාලට හිතාගන්න පුලුවන්නේද UNIX / Linux වල තියෙන පොඩි පොඩි දේවල් අපි හිතනවටවඩා හුගක් බලගතුයි කියල. මේ වගේ දේවල් කරන ආකාරයත් ඔයාලට ඉදිරියේදී කියල දෙන්න තමයි මගේ අදහස. අද ටිකක් විතර මහන්සියි . මට මේක ඊයේ ඉවරකර ගන්න බැරිවුණා. ගෙදර පොඩි අයගෙ school වැඩ ටිකක් තිබුන. අලුත් පාඩමකින් හමුවෙමු. ස්තුතියි![/SIZE] [URL="http://www.elakiri.com/forum/showthread.php?p=21854337#post21854337"][SIZE="4"]DevOps_UNIX / Linux_9_UNIX / Linux Presesses ගැන දැන ගනිමු පළමු කොටස[/SIZE][/URL] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom