½ÃÀÛÆäÀÌÁö·Î Áñ°Üã±âÃß°¡
·Î±×ÀÎ
ȸ¿ø°¡ÀÔ l Ã⼮üũ l ¸¶ÀÌÆäÀÌÁö l CGIMALL
ÀÚ·á½Ç »çÀÌÆ®µî·Ï ·©Å·100 ÇÁ·Î±×·¥¸®ºä °ü¸®ÀÚÃßõÀÚ·á Ãʺ¸°¡À̵å
Ä¿¹Â´ÏƼ
Àüü ÆîÃ帱â
Äü¸Þ´º¸µÅ© jquery , CSS , PHP , Javascript , ¹«·áÆùÆ® , ASP
»ó¼¼°Ë»ö
Ȩ > Ä¿¹Â´ÏƼ > °ñµåÆÁ »ó¼¼º¸±â
Ä¿¹Â´ÏƼ ±¸Àα¸Á÷
»çÀÌÆ®µî·Ï
Ŭ¶ó¿ìµåű×
Javascript
PHP
ASP
CSS
HTML
mysql
jquery
image
API
mobile
¸Þ´º
slide
°Ô½ÃÆÇ
ÇöÀçÁ¢¼ÓÀÚ ¸í »õ·Î°íħ
°Ô½ÃÆÇŸÀÌƲ °ñµåÆÁ / »ó¼¼º¸±â
Æ®À§ÅÍ·Î º¸³»±â
Ãßõ¼ö 305 | Á¶È¸¼ö 3,131 | µî·ÏÀÏ 2002-06-03 17:06:08

´Ð³×ÀÓ

HappyCGI

Á¦¸ñ

´Ù¸¥ ÇÁ·Î±×·¥À» ½ÇÇà½ÃÄÑ Ãâ·Â³»¿ë Àбâ
³»¿ë
´Ù¸¥ ÇÁ·Î±×·¥À» ½ÇÇà½ÃÅ°°í ±× Ãâ·Â ³»¿ëÀ» Àд ¹æ¹ýÀº ¿©·¯°¡Áö°¡ ÀÖ½À´Ï´Ù. ¸¹Àº ºÐµéÀÌ ¾Ë°í °è½ÃÁö¸¸, ¸î¸î ¸ð¸£½Ã´Â ºÐµéÀ» À§ÇØ ¿©±â ±× ¹æ¹ýµéÀ» ¼Ò°³ÇÕ´Ï´Ù. Backtick ¿ªµû¿ÈÇ¥(`...`)´Â ±× ¾È¿¡ µé¾îÀÖ´Â ³»¿ëÀ» shellÀ» ÅëÇØ ½ÇÇàÇÏ°í, Ç¥ÁØÃâ·Â(STDOUT)À¸·Î Ãâ·ÂµÇ´Â ³»¿ëÀ» ¹ÝȯÇÕ´Ï´Ù. µû¶ó¼­, $content = `cat /etc/passwd`; ´Â passwd ÆÄÀÏÀ» °£´ÜÈ÷ ÀоîµéÀÔ´Ï´Ù. ¹°·Ð, ´Ü¼øÇÑ ÆÄÀÏÀ» Àдµ¥´Â Á÷Á¢ openÀ» Çؼ­ ÀоîµéÀÌ´Â °ÍÀÌ ÁÁ½À´Ï´Ù. ¿ªµû¿ÈÇ¥¸¦ »ç¿ëÇÏ°Ô µÇ¸é, ±× ³»ºÎÀÇ ÇÁ·Î±×·¥À» ½ÇÇàÇϱâ À§Çؼ­ º°µµÀÇ ÇÁ·Î¼¼½º°¡ »ý¼ºµÇ¾î¾ß Çϱ⠶§¹®¿¡ ±×¸¸Å­ ½Ã½ºÅÛÀÇ ÀÚ¿øÀ» ¼Ò¸ðÇϰԵ˴ϴÙ. open ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ´Â ¹æ¹ý open ÇÔ¼ö¿¡¼­ ÆÄÀÏÀ̸§ºÐ¿¡ > ´ë½Å | (ÆÄÀÌÇÁ)±âÈ£¸¦ µÚ¿¡ ºÙÀ̸é ÇØ´ç ÆÄÀÏÀ̸§À» ½ÇÇà½ÃÅ°°í ±× Ãâ·Â³»¿ëÀ» ÀÐÀ» ¼ö ÀÖ½À´Ï´Ù.
[ÇÁ·Î±×·¥ÄÚµå]
#!/usr/bin/perl # prog.pl print "$$\n"; warn "Exiting\n"; #!/usr/bin/perl # opener.pl $p = open(RUN, "./prog.pl |") || die $!; # ./prog.pl µÚ¿¡ | Ç¥½Ã. @out = <RUN>; close RUN; # ¹Ýµå½Ã ÇϽʽÿÀ. print "opener: $p\n"; print map { "opener: $_" } @out;

opener.pl¿¡¼­ prog.plÀ» "./prog.pl |"¿Í °°ÀÌ ÇÏ¿© ¿­¾ú½À´Ï´Ù.(open) ±× ÈÄ ÀÏ¹Ý ÆÄÀÏ Àб⿡¼­ ÇÏ´Â °Íó·³ <RUN>¸¦ ÀÌ¿ëÇÏ¿© Ãâ·Â³»¿ëÀ» ÀнÀ´Ï´Ù. Âü°í·Î, open ÇÔ¼ö°¡ ¹ÝȯÇÏ´Â °ÍÀº, ÇÁ·Î±×·¥ÀÌ Á¦´ë·Î ½ÇÇàµÇ¾úÀ» ¶§, »õ·Î¿î ÇÁ·Î¼¼½ºÀÇ ÇÁ·Î¼¼½º ¾ÆÀ̵ðÀÔ´Ï´Ù. ¸¸ÀÏ ÀÌ ÇÁ·Î±×·¥ÀÌ ¿À·£½Ã°£µ¿¾È »ì¾Æ ÀÖ´Â °Í(À¥¼­¹öó·³)À̶ó¸é close¸¦ ÇÏÁö ¾ÊÀ» °æ¿ì ¹®Á¦°¡ µÉ ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î, openÀº °è¼ÓÇØ¾ß Çϴµ¥, close¸¦ ÇØ ÁÖÁö ¾Ê´Â´Ù¸é, ÇØ´ç ÇÁ·Î¼¼½º°¡ Á×Áö¾Ê°í °è¼Ó ³²¾Æ¼­ ½Ã½ºÅÛÀÚ¿øÀ» Â÷ÁöÇÏ°í À־ °á±¹ ½Ã½ºÅÛÀÌ ¸ØÃß´Â »óȲÀÌ ¹ß»ýÇÒ ¼öµµ ÀְԵ˴ϴÙ. µû¶ó¼­ ¹Ýµå½Ã close¸¦ ÇØ ÁÖ¾î¾ß ÇÕ´Ï´Ù. ¸¸ÀÏ Ç¥ÁØ¿¡·¯(STDERR)±îÁö °°ÀÌ Àоî¾ß ÇÑ´Ù¸é
[ÇÁ·Î±×·¥ÄÚµå]
#!/usr/bin/perl # prog.pl print "$$\n"; warn "Exiting\n"; #!/usr/bin/perl # opener.pl $p = open(RUN, "./prog.pl 2>&1 |") || die $!; # ./prog.pl µÚ¿¡ | Ç¥½Ã. @out = <RUN>; close RUN; # ¹Ýµå½Ã ÇϽʽÿÀ. print "opener: $p\n"; print map { "opener: $_" } @out;

¿Í °°ÀÌ 2>&1¸¦ Ãß°¡ÇÕ´Ï´Ù. ÀÌ ±ÛÀº http://www.perl.or.kr/tips/readoutput.html ¿¡¼­ ¹ßÃéµÈ ±ÛÀÔ´Ï´Ù.
Ãßõ½ºÅ©·¦¼Ò½ºº¸±â ¸ñ·Ï
ÀÌÀü°Ô½Ã±Û ÆÞ¸ðµâ µ¿ÀûÀ¸·Î ·ÎµåÇϱâ (use¿Í requireÀÇ Â÷ÀÌÁ¡) 2002-06-03 17:04:17
´ÙÀ½°Ô½Ã±Û ³¯Â¥ ÆÐÅÏ °Ë»ç¿Í ÈÄÂüÁ¶(backreference) 2002-06-03 17:07:50