[초보]perl 관련 추가 질문 드립니다.

bluesolip의 이미지

추가로 질문 드립니다.

my $RESULT= 'perl --version';
=>$RESULT를 프린트하면 정상적으로 버전이 들어가 있음

my $RESULT= 'armcc' <- 여기 코드에서 바로 cmd창에 뿌려줌
=>$RESULT를 프린트하면 NULL임

같은 perl코드상에서 왜 이와 같이 다르게 동작하는지 알수 가 없습니다.
도움 부탁드려요.

bluesolip의 이미지

또한 만약 my $RESULT에 정상적으로 version정보를 넣고 싶으면 어떻게 해야 하나요??
원래 코드는
my $RESULT= 'perl --version 2>&1';
my $RESULT= 'armcc 2>&1';
이었습니다.
이때에는 $RESULT 값은 둘다 동일하게 ""으로 NULL값입니다.

최종호의 이미지

저는 결과가 틀린데요.

armcc 는 프로그램이 없어서 테스트를 못했지만,
my $RESULT= `perl --version 2>&1`;
는 정상적으로 $RESULT 에 결과가 들어갑니다.

혹시 ` (back quote) 를 ' (single quote) 로 잘못 쓰신 건 아닌가 생각되지만
그 경우에는 $RESULT에 'perl --version 2>&1' 이 그대로 들어가 있어야 하기 때문에
역시나 말씀해 주신 결과와는 틀립니다.

bluesolip의 이미지

우선 답변은 감사드립니다.

`(back quote)는 제대로 썼어요.
my $RESULT= `perl --version 2>&1`; => my $RESULT= `perl --version`;
my $RESULT= `armcc 2>&1`; => my $RESULT= `armcc`;
로 코드를 변경해서 해봤지만
my $RESULT= `perl --version`; 이 코드는 정상적으로 $RESULT에 값이 들어가지만
my $RESULT= `armcc`; 이 코드는 바로 dos창에 뿌려주고 $RESULT에는 아무 값도 없습니다.
너무 이상해서 이것저것 해봤지만 잘 안되네요.

aero의 이미지

`명령`; 은 표준출력(STDOUT)을 통해 출력되는 것만 결과로 넘어옵니다.
2>&1 이란의미는 에러출력(STDERR - 디스크립트번호 2)이 있으면 표준입력(STDOUT 1)로 돌려란 의미입니다.

`perl --version` 은 결과를 STDOUT으로 뿌려줍니다.
`perl --version 2>&1` 은 에러출력으로 나오는 것이 있을시 그것도 같이 STDOUT으로 뿌려줍니다.
perl --version은 모두 STDOUT으로 뿌려주기 때문에 실제 2>&1 이 필요가 없습니다.

그럼 my $RESULT= `armcc`; 이 왜 $RESULT에 아무것도 안들어가고 2>&1이 들어가야 되는지 추리가 되시겠죠?

이건 Perl 이해 의 문제가 아니고 UNIX Shell 이해의 문제인 것 같네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.