[Cascavel-pm] Comando cat | wc -l

Vinicius Alves perl em atechs.com.br
Segunda Junho 26 17:40:12 PDT 2006


Alceu,

system() executa um comando em background mas não retorna seu output. 

` ` retorna seu output e armazena.

teste isso (teste.pl):


#!/usr/bin/perl

$var = system("echo 12345");
print "\$var = $var\n";
$var2 = `echo 12345`;
print "\$var2 = $var2\n";

Resultado:
>./teste.pl
12345
$var = 0
$var2 = 12345

A diferença entre system() e exec() é que system retorna ao programa do qual foi chamado. Exec não retorna. Backtick operator retorna o output de seu programa à variável, system() não (ou retorna true/false - aí já não tenho certeza).

[]'s
Vinicius


  ----- Original Message ----- 
  From: Alceu R. de Freitas Jr. 
  To: Cascavel Perl Mongers 
  Sent: Monday, June 26, 2006 11:05 AM
  Subject: Re: [Cascavel-pm] Comando cat | wc -l



  --- Vinicius Alves <perl em atechs.com.br> escreveu:

  > Patty,
  > 
  > A função system() não retorna nada. Se quiser
  > retorno, use 

  Retorna sim. Quem não retorna nada é o exec().



  Alceu Rodrigues de Freitas Junior
  --------------------------------------
  glasswalk3r em yahoo.com.br
  http://www.imortais.cjb.net
  -----------------------------------------------------------------------
  A well-used door needs no oil on its hinges.
  A swift-flowing stream does not grow stagnant.
  Neither sound nor thoughts can travel through a vacuum.
  Software rots if not used.
  These are great mysteries -- The Tao Of Programming, 5.1



  _______________________________________________________ 
  Abra sua conta no Yahoo! Mail: 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz. 
  http://mail.yahoo.com.br/
  _______________________________________________
  Cascavel-pm mailing list
  Cascavel-pm em pm.org
  http://mail.pm.org/mailman/listinfo/cascavel-pm



  -- 
  No virus found in this incoming message.
  Checked by AVG Free Edition.
  Version: 7.1.394 / Virus Database: 268.9.3/374 - Release Date: 23/6/2006

-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: http://mail.pm.org/pipermail/cascavel-pm/attachments/20060626/e2c0abc5/attachment.html 


Mais detalhes sobre a lista de discussão Cascavel-pm