<br><br><div class="gmail_quote">2008/12/11 Joao Gabriel <span dir="ltr">&lt;<a href="mailto:jamorreu@gmail.com">jamorreu@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
As vezes 56 linhas bem comentadas valem mais do que 29 e-mails na qual<br>
50% ou 60% estão discutindo bobeiras sobre Japh...</blockquote><div>Claro, olha o nome do cara &#39;Daniel&#39; precisa falar mais alguma coisa ? <br>hahahaha <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<font color="#888888"><br>
<br>
--<br>
João Gabriel C. Laass<br>
<br>
<br>
<br>
2008/12/11 Daniel Ruoso &lt;<a href="mailto:daniel@ruoso.com">daniel@ruoso.com</a>&gt;:<br>
</font><div><div></div><div class="Wj3C7c">&gt; Em Ter, 2008-12-09 às 03:35 -0800, Patty Silva escreveu:<br>
&gt;&gt; Pessoal,<br>
&gt;&gt; Tem como eu imprimir na tela &quot;Loading .................&quot; quando<br>
&gt;&gt; executa o system??<br>
&gt;<br>
&gt; Olá,<br>
&gt;<br>
&gt; Pessoal, eu tenho me mantido meio calado ultimamente, mas vendo esse<br>
&gt; thread enorme sem ninguem dar a solução para um problema que, precisamos<br>
&gt; reconhecer, não é &quot;de iniciante&quot;, resolvi dar a solução...<br>
&gt;<br>
&gt; A resposta curta é: &quot;Não use system&quot;.<br>
&gt;<br>
&gt; A resposta longa é:<br>
&gt;<br>
&gt;<br>
&gt; #!/usr/bin/perl<br>
&gt; use strict;<br>
&gt; use warnings;<br>
&gt;<br>
&gt; use Symbol;<br>
&gt; # essa linha define símbolos para os três filehandles,<br>
&gt; # acho que eu vi isso pela primeira vez no PBP<br>
&gt; my ($wtr, $rdr, $err) = map { gensym } 1..3;<br>
&gt;<br>
&gt; use IPC::Open3;<br>
&gt; my $pid = open3($wtr, $rdr, $err,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39;ls&#39;, &#39;-la&#39;);<br>
&gt;<br>
&gt; # considerando que o comando não recebe nada pelo stdin<br>
&gt; close $wtr;<br>
&gt;<br>
&gt; # usar o IO::Handle é legal porque ele dá uma visão OO sobre<br>
&gt; # os filehandles, o que facilita algumas coisas...<br>
&gt; use IO::Handle;<br>
&gt; # por exemplo:<br>
&gt; $_-&gt;blocking(0) for ($rdr, $err);<br>
&gt; STDOUT-&gt;autoflush(1);<br>
&gt;<br>
&gt; # usar o IO::Select também é legal, porque te permite acompanhar<br>
&gt; # filehandles de uma maneira mais esperta<br>
&gt; use IO::Select;<br>
&gt; my $sel = IO::Select-&gt;new($rdr, $err);<br>
&gt;<br>
&gt; # vamos fazer um loop, e ver se o comando escreveu alguma coisa,<br>
&gt; # se ele não escrever em 1 segundo, imprimimos um &quot;.&quot;<br>
&gt; while (1) {<br>
&gt; &nbsp;my @ready = $sel-&gt;can_read(1000);<br>
&gt; &nbsp;foreach my $io (@ready) {<br>
&gt; &nbsp; &nbsp;my $type = $io == $rdr ? &#39;[STDOUT]&#39; : &#39;[STDERR]&#39;;<br>
&gt;<br>
&gt; &nbsp; &nbsp;# Como estamos fazendo leitura não bloqueante, não devemos<br>
&gt; &nbsp; &nbsp;# usar &lt;$io&gt;...<br>
&gt; &nbsp; &nbsp;if (read $io, my $buf, 1024) {<br>
&gt; &nbsp; &nbsp; &nbsp;print $type, &#39; &#39;, $buf, $/;<br>
&gt; &nbsp; &nbsp;} else {<br>
&gt; &nbsp; &nbsp; &nbsp;# se read retornar 0 ou undef, é porque acabou o arquivo ou tem<br>
&gt; &nbsp; &nbsp; &nbsp;# algum erro no filehandle, então vamos tirar do select.<br>
&gt; &nbsp; &nbsp; &nbsp;$sel-&gt;remove($io);<br>
&gt; &nbsp; &nbsp;}<br>
&gt; &nbsp;}<br>
&gt;<br>
&gt; &nbsp;# imprime o pontinho...<br>
&gt; &nbsp;print &#39;.&#39; unless @ready;<br>
&gt;<br>
&gt; &nbsp;# sai se não tem mais nenhum filehandle<br>
&gt; &nbsp;last unless scalar $sel-&gt;handles;<br>
&gt; };<br>
&gt;<br>
&gt;<br>
&gt; # espera o processo sair de verdade;<br>
&gt; waitpid $pid, 0;<br>
&gt;<br>
&gt; __END__<br>
&gt;<br>
&gt;<br>
&gt; e é isso aí...<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Cascavel-pm mailing list<br>
&gt; <a href="mailto:Cascavel-pm@pm.org">Cascavel-pm@pm.org</a><br>
&gt; <a href="http://mail.pm.org/mailman/listinfo/cascavel-pm" target="_blank">http://mail.pm.org/mailman/listinfo/cascavel-pm</a><br>
&gt;<br>
_______________________________________________<br>
Cascavel-pm mailing list<br>
<a href="mailto:Cascavel-pm@pm.org">Cascavel-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/cascavel-pm" target="_blank">http://mail.pm.org/mailman/listinfo/cascavel-pm</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Procuro emprego C.V:<br><a href="http://danielmantovani.awardspace.com/">http://danielmantovani.awardspace.com/</a><br><br>print &quot;\x54\x68\x65\x20\x53\x69\x6c\x65\x6e\x74\x20\x47\x75\x61\x72\x64\x69\x61\x6e&quot;,$/<br>
<br>