[28486] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9850 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 15 18:06:05 2006

Date: Sun, 15 Oct 2006 15:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 15 Oct 2006     Volume: 10 Number: 9850

Today's topics:
    Re: alarm() - SIGALRM sent too eariy? <rvtol+news@isolution.nl>
    Re: alarm() - SIGALRM sent too eariy? bwooster47@gmail.com
    Re: alarm() - SIGALRM sent too eariy? <tadmc@augustmail.com>
    Re: alarm() - SIGALRM sent too eariy? bwooster47@gmail.com
    Re: alarm() - SIGALRM sent too eariy? <bik.mido@tiscalinet.it>
    Re: alarm() - SIGALRM sent too eariy? <hjp-usenet2@hjp.at>
    Re: alarm() - SIGALRM sent too eariy? anno4000@radom.zrz.tu-berlin.de
    Re: alarm() - SIGALRM sent too eariy? <rvtol+news@isolution.nl>
    Re: Archive::Zip - end up with empty file ... <lev.weissman@creo.com>
    Re: Can't redirect STDOUT <Peter@PSDT.com>
    Re: problems appending an entry to a logfile <tadmc@augustmail.com>
    Re: problems appending an entry to a logfile (reading news)
    Re: problems appending an entry to a logfile anno4000@radom.zrz.tu-berlin.de
        sending ctrl+C to pipe process <gweissenseel@yahoo.com>
    Re: sending ctrl+C to pipe process <sherm@Sherm-Pendleys-Computer.local>
    Re: sending ctrl+C to pipe process <gweissenseel@yahoo.com>
    Re: sending ctrl+C to pipe process anno4000@radom.zrz.tu-berlin.de
    Re: trouble merging files using nested loop to read fil (reading news)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 15 Oct 2006 12:33:06 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <egt9qi.1m4.1@news.isolution.nl>

bwooster47@gmail.com schreef:
> anno4000:

>> ... and this one aren't the same.
>
> This was just an example, the code used is correct,
> was just a typo in my posting.

It is not 'just a typo', it is wasting everybody's time.

Always use copy-and-paste, and only present the shortest complete code
that 1. shows your problem, and that 2. we can run, and that 3. contains
"use warnings ; use strict ;".

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: 15 Oct 2006 04:31:33 -0700
From: bwooster47@gmail.com
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <1160911893.627978.151890@k70g2000cwa.googlegroups.com>

Peter J. Holzer wrote:
> On 2006-10-15 00:27, bwooster47@gmail.com <bwooster47@gmail.com> wrote:
>
> 110 minutes =3D=3D 6_600 seconds =3D=3D 6_600_000_000 =B5s.
> 6_600_000_000 % 2^32 =3D=3D 2_305_032_704 =B5s =3D=3D 38.417 minutes.
>
> So my guess is that the time before the alarm is converted to
> microseconds before being passed to the OS and that an integer overflow
> happens during the conversion
>=2E..........................
> setitimer(ITIMER_REAL, {it_interval=3D{0, 0}, it_value=3D{0, 2305032704}},
> {it_interval=3D{0, 0}, it_value=3D{0, 0}}) =3D 0
>
> The parameter it_value is wrong. It should be {6600, 0} instead of {0,
> 2305032704}.
>
> Probably a bug in Time::HiRes. Without use Time::HiRes, alarm(6600) is
> called, which is correct.

Bingo! Thanks a lot for this explanation, I tried a few more tests,
this looks like a issue with Time::HiRes - did not find any mention of
similar issues in the docs, so may be an bug?

In any case, since I don't need that level of time resolution, I've
removed it from my code, and it now works fine with the standard
alarm().

Here's the output of the script "t.pl"
    perl t.pl 6600
    Got alarm, signal ALRM, time taken 2305.03450393677

and here's t.pl:

more t.pl -------------------------------------------------------------
# run as: give one argument, number of seconds for alarm() call
use Time::HiRes qw ( time alarm ); # bug - can't handle alarm  if
32-bit mircosecs overflows??
my $signal =3D "";
my $t =3D 0;
my $t1 =3D time();

alarm(shift);

$SIG{'ALRM'} =3D sub {
    $signal =3D shift; $t =3D time() - $t1;
    die "Got alarm, signal $signal, time taken $t\n";
};

while (<>) { } # infinite loop, read from stdin, throw away read data
(if any)
---------------------------------------

Should I report this somewhare, or do the authors of Time::HiRes read
this newsgroup?

In any case, thanks for the precise reply.



------------------------------

Date: Sun, 15 Oct 2006 08:28:39 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <slrnej4ds7.gut.tadmc@magna.augustmail.com>

bwooster47@gmail.com <bwooster47@gmail.com> wrote:
> anno4000@radom.zrz.tu-berlin.de wrote:
>> >     last if ($timerexpired);
>>                 ^^^^^^^^
>> ... and this one aren't the same.
> 
> This was just an example, the code used is correct, was just a typo in
> my posting.


Have you seen the Posting Guidelines that are posted here frequently?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 15 Oct 2006 09:57:23 -0700
From: bwooster47@gmail.com
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <1160931442.956884.215290@e3g2000cwe.googlegroups.com>

Tad McClellan wrote:
> bwooster47@gmail.com <bwooster47@gmail.com> wrote:
> > anno4000@radom.zrz.tu-berlin.de wrote:
> >> >     last if ($timerexpired);
> >>                 ^^^^^^^^
> >> ... and this one aren't the same.
> >
> > This was just an example, the code used is correct, was just a typo in
> > my posting.
> Have you seen the Posting Guidelines that are posted here frequently?


Amazing, so many of the replies to my post were merely asking RTFM.

I was looking for tips in my first post - anyone reading it would see
the many ellipses (...) and "do reads" etc comments - as my last
paragraph said, I was looking for hints/tips/pointers on what to look
for next - related to signals, I/O, and Time::HiRes.
I specifically did not post code, since I was going to do the legwork,
and create a sample based on responses of what should the focus be on -
signals? I/O? Or known bug?

Clearly, far more important to post code here, and not exchange ideas.

[Posting code to usenet? Did you see how the lines get folded by
newsreaders? Does anyone think cut-n-paste of the EXACT program I
submitted in the last posting, would work? ]



------------------------------

Date: 15 Oct 2006 19:50:46 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <egs4j2tsiogtdg5qan8civkjgmdo0uv56h@4ax.com>

On 15 Oct 2006 09:57:23 -0700, bwooster47@gmail.com wrote:

>> Have you seen the Posting Guidelines that are posted here frequently?
>
>Amazing, so many of the replies to my post were merely asking RTFM.

Yes, it's customary here. It makes discussion more efficient. It was
not exactly about the FM, but about the posting guidelines, which in
turn are not the Law, but comprise a series of recommendations out of
common sense. Some poster do not even need them. Some are better
pointed to them. Most knowledgeable, resourceful, helpful regulars
here just prefer that one helps them to help him or her by respecting
those guidelines. Live with that! If one has some problem with some
code, then there's nothing unreasonable in wanting to see a minimal
but complete amount of code exhibiting the problem.

>I was looking for tips in my first post - anyone reading it would see
>the many ellipses (...) and "do reads" etc comments - as my last
>paragraph said, I was looking for hints/tips/pointers on what to look
>for next - related to signals, I/O, and Time::HiRes.

Indeed, and you *were* helped, weren't you?

>I specifically did not post code, since I was going to do the legwork,
>and create a sample based on responses of what should the focus be on -
>signals? I/O? Or known bug?

Personally I don't think you did anything terrible, but it's a matter
of fact that retyping code ad hoc produced a spurious typo, which is
not respectful of the people you're asking help to. I, and most
others, reminded you why it is better to paste than to retype. Typing
in your editor shouldn't be much more difficult than in your news
client (they may even actually be the same), and a paste is click or
keybinding away.

>Clearly, far more important to post code here, and not exchange ideas.

It just gets difficult -sometimes- to exchange ideas about code
without code to see. Discussing the wheather is a whole another story,
of course!

>[Posting code to usenet? Did you see how the lines get folded by
>newsreaders? Does anyone think cut-n-paste of the EXACT program I
>submitted in the last posting, would work? ]

Strangely enough most us can cope with that on a daily basis. If I'm
going to prepare some sample code to post here I'll take care not to
write too long lines. Well, as far as I'm concened I customarily avoid
long lines anyway...


HTH,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Sun, 15 Oct 2006 20:40:12 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <slrnej504c.2em.hjp-usenet2@yoyo.hjp.at>

On 2006-10-15 16:57, bwooster47@gmail.com <bwooster47@gmail.com> wrote:
> I was looking for tips in my first post - anyone reading it would see
> the many ellipses (...) and "do reads" etc comments

The problem with this approach is that it makes it difficult for the
reader to see where the problem is - it might be in the code you posted
or in the code you didn't post. Anno seems to have been confused by
this: He concentrated on typos in your code and missed your remark that
the problem only occurs for times of more than 2000 seconds.  When his
test case worked well for 1800 seconds he concluded that all was well
and the error must be somewhere else.
I was also almost convinced that the problem had to be in a part you
didn't post when I noticed the relationship between 38-point-something
minutes and 110 minutes.

> Clearly, far more important to post code here, and not exchange ideas.

English is a rather vague language. So if you can express your ideas in
Perl, Perl is preferred.


> [Posting code to usenet? Did you see how the lines get folded by
> newsreaders? Does anyone think cut-n-paste of the EXACT program I
> submitted in the last posting, would work? ]

I copy code from this newsgroup all the time, and I rarely have to fix
it before I can run it.
It takes a bit of discipline on the part of the poster: Avoid long
lines, avoid invisible characters (e.g. tabs) where they matter, keep
the code short, etc. But in editing your code so that it is fit for a
discussion group (you are completely correct that this is a discussion
group, not a source code repository), you often can find the problem
yourself or at least make it easy for others to spot the problem.

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: 15 Oct 2006 20:48:43 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <4pfl5bFil8csU1@news.dfncis.de>

Peter J. Holzer <hjp-usenet2@hjp.at> wrote in comp.lang.perl.misc:
> On 2006-10-15 16:57, bwooster47@gmail.com <bwooster47@gmail.com> wrote:
> > I was looking for tips in my first post - anyone reading it would see
> > the many ellipses (...) and "do reads" etc comments
> 
> The problem with this approach is that it makes it difficult for the
> reader to see where the problem is - it might be in the code you posted
> or in the code you didn't post. Anno seems to have been confused by
> this: He concentrated on typos in your code and missed your remark that
> the problem only occurs for times of more than 2000 seconds.  When his
> test case worked well for 1800 seconds he concluded that all was well
> and the error must be somewhere else.

Yes, for some reason I thought the error ought to show for 1800 seconds.

Re-running the test I find that Time::HiRes 1.66 works correctly for
2700 secs (Time taken (Seconds): 2699.98529100418), so if it's a
bug in Time::HiRes it appears to be resolved.

Anno


------------------------------

Date: Sun, 15 Oct 2006 22:48:06 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <egue2n.ds.1@news.isolution.nl>

bwooster47@gmail.com schreef:

> Amazing, so many of the replies to my post were merely asking RTFM.

If even so, you could have prevented it by applying the Posting
Guidelines, that are posted here twice a week.


> I specifically did not post code, since I was going to do the legwork,
> and create a sample based on responses of what should the focus be on
> - signals? I/O? Or known bug?

As Peter an many before him stated: "in editing your code so that it is
fit for a discussion group [...], you often can find the problem
yourself or at least make it easy for others to spot the problem."

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: 15 Oct 2006 03:40:58 -0700
From: "MoshiachNow" <lev.weissman@creo.com>
Subject: Re: Archive::Zip - end up with empty file ...
Message-Id: <1160908858.643235.193870@b28g2000cwb.googlegroups.com>

>I see nothing in the docs for Archive::Zip that indicates $! is set on
>a failure.  Print out the return value of the method, and compare it to
>the values listed in the documentation.  That will tell you what the
>problem is.

>Paul Lalli

Thanks,a good idea.
How do I actualy print these codes ?I could not figure out.
Thanks



------------------------------

Date: Sun, 15 Oct 2006 12:52:43 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Can't redirect STDOUT
Message-Id: <pan.2006.10.15.13.00.46.919640@PSDT.com>

On Sat, 14 Oct 2006 09:50:15 -0700, Brian McCauley wrote:
[snip amazingly clear and concise explanation]
> But if you do local(*STDOUT) you stash away the current contents of
> *STDOUT{IO} and make it empty. Now when you open(STDOUT,...) you get a
> new IO-thingy associated with *STDOUT{IO} but this IO-thingy is not
> associated with FD 1.  As far as the current Perl process is concerned
> this is now the "standard output" but any child process that's created
> will still think of FD 1 as standard out.

Although it's clear in the context of the post you were replying to, since
your posting is worth saving for posterity and repeating, it's worth
clarifying that "child process" there refers to a program that's been
exec()ed in some way, not a fork()ed perl process that'll still be using
the copied IO-thingy:

$ rm /tmp/stdout; perl -le 'local *STDOUT; \
  open STDOUT, ">/tmp/stdout"; print "parent"; \
  exit if fork; print "perl child"; \
  exec "echo shell call"' 
shell call
$ cat /tmp/stdout
parent 
perl child

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/



------------------------------

Date: Sun, 15 Oct 2006 08:45:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problems appending an entry to a logfile
Message-Id: <slrnej4er3.gut.tadmc@magna.augustmail.com>

markpark <mark.leeds@morganstanley.com> wrote:

> i just want to append a new line ( with the date, time, entry number
> and my login name )  to
> a file 


> open my $LOG_FILE, '<', $logfile or die "could not open $logfile for
> reading: !";
         ^^^


You are missing a dollar sign there.

The $! special variable contains the reason for the failure
such as "permission denied" or "file not found".


> while (<$LOG_FILE>) {
>   chomp;
>   my @items = split / /;
>   $lastone = $items[$#items] + 1;
> }
> 
> close $LOG_FILE;
> 
> my $tm = localtime;
> my($month,$year,$mday,$hour,$min,$sec) = ($tm->mon, $tm->year,
> $tm->mday, $tm->hour, $tm->min, $tm->s
> 
> open $LOG_FILE, '>>', $logfile or die "could not open $logfile for
> appending !";
> 
> print $LOG_FILE " $year $month $mday $hour . "::" . $min . "::" . $sec
> $lastone \n";
> close $LOG_FILE;
> 
> return(1)


Why do you include that return statement?


> }
> 
> 
> i would like my logfile to look like
> 
> 2006 10 14 01:33:06 1  leedsmar
> 2006 10 14 01:33:06 2  leedsmar
> 2006 10 14 01:33:06 3  leedsmar
                       ^^
                       ^^

Then you will have *seven* fields per line and the sixth one will
always be the empty string, given your split() pattern above...


> 1) how to format my values so the line can look like above

   perldoc -f printf


> 2) somehow use the "whoami" at the prompt to get the login name into a
> variable called
> say $login_name

   chomp(my $login_name = `whoami`);
or
   chomp(my $login_name = qx/ whoami /);


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 15 Oct 2006 20:14:19 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: problems appending an entry to a logfile
Message-Id: <vEwYg.14211$UG4.929@newsread2.news.pas.earthlink.net>

On 10/15/2006 01:02 AM, markpark wrote:
> hi all : i definitely went through all the books ( learning perl, perl
> cookbook and programming perl )
> and i found discussions of what i want to do but not enough for me to
> get it right
> ( given ym perl ability. i'm not blaming it on the books ).
> 
> i just want to append a new line ( with the date, time, entry number
> and my login name )  to
> a file that already  has previous lines ( of the same exact format with
> all fields seprated by whitespace ) it and i'm pretty close. the new
> line would differ in terms of the entry
> number and the date but otherwise it's exactly the same as the previous
> lines
> that already in the file.
> 

You can use Uri Guttman's File::Slurp to make the appending easy.

> so, i wrote a subroutine , logFileEntry,  which would take the
> logfilename as input
> 
> the code is below.
> 
> ---------------------------------------------------------------------------------------------------------------------------------------------
> 
> sub logFileEntry {
> 
> my $logfile = shift;
> 
> my $lastone = 0;
> 
> open my $LOG_FILE, '<', $logfile or die "could not open $logfile for
> reading: !";
> 
> while (<$LOG_FILE>) {
>   chomp;
>   my @items = split / /;
>   $lastone = $items[$#items] + 1;
> }
> 
> close $LOG_FILE;
> 
> my $tm = localtime;
> my($month,$year,$mday,$hour,$min,$sec) = ($tm->mon, $tm->year,
> $tm->mday, $tm->hour, $tm->min, $tm->s
> 

Perl is not C. In scalar context, localtime() returns a string 
containing the local time. You almost certainly want to call localtime 
in list context so that you can get the values in separate array 
elements, e.g.

my @lcdata = localtime;
my ($month, $year, $mday, $hour, $min, $sec) = @lcdata[4,5,3,2,1,0];


> open $LOG_FILE, '>>', $logfile or die "could not open $logfile for
> appending !";
> 
> print $LOG_FILE " $year $month $mday $hour . "::" . $min . "::" . $sec
> $lastone \n";
> close $LOG_FILE;
> 
> return(1)
> 
> }
> 
> 
> i would like my logfile to look like
> 
> 2006 10 14 01:33:06 1  leedsmar
> 2006 10 14 01:33:06 2  leedsmar
> 2006 10 14 01:33:06 3  leedsmar
> ..
> ..
> ..
> ..
> 
> but my two problems are
> 
> 1) how to format my values so the line can look like above
> 

Add 1900 to the year returned by localtime, and format the minutes and 
seconds using sprintf.


> 2) somehow use the "whoami" at the prompt to get the login name into a
> variable called
> say $login_name
> 

The "qx" operator allows you to call external programs such as "whoami."


> again, i've really tried and i found info in different books but i
> still can't gt it quite right. thank you
> very much to anyone who can help me. i'm sorry to be such a pest to the
> list but
> i don't know what else to do. I'm really trying.
> 

Here is a example:

use strict;
use warnings;
use File::Slurp;
my $lastone = 0;

sub logFileEntry {
     my $logfile = shift;
     my @lc = localtime;
     my $who = qx(whoamii); # whoamii is valid on my system
     chomp $who;

     $lc[5] += 1900;
     @lc[0,1] = map sprintf("%02d",$_), @lc[0,1];

     write_file $logfile, {append => 1} ,
         " $lc[5] $lc[4] $lc[3] $lc[2]::$lc[1]::$lc[0] $lastone $who\n"
         or die ("Could not open $logfile for appending: $!");
     $lastone++;
}

__END__

Please read these important Perl documents:

perldoc -f localtime
perldoc -q "output of a command"
perldoc File::Slurp


-- 
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.


------------------------------

Date: 15 Oct 2006 20:59:10 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: problems appending an entry to a logfile
Message-Id: <4pflouFil8csU2@news.dfncis.de>

Mumia W. (reading news) <paduille.4059.mumia.w@earthlink.net> wrote in comp.lang.perl.misc:
> On 10/15/2006 01:02 AM, markpark wrote:

[...]

> > my $tm = localtime;
> > my($month,$year,$mday,$hour,$min,$sec) = ($tm->mon, $tm->year,
> > $tm->mday, $tm->hour, $tm->min, $tm->s
> > 
> 
> Perl is not C. In scalar context, localtime() returns a string 
> containing the local time. You almost certainly want to call localtime 
> in list context so that you can get the values in separate array 
> elements, e.g.

I suspect "use Time::localtime" is in effect, which would make the
code above work (after fixing the truncated statement).

Anno


------------------------------

Date: 15 Oct 2006 05:54:08 -0700
From: "linbox" <gweissenseel@yahoo.com>
Subject: sending ctrl+C to pipe process
Message-Id: <1160916848.017794.75910@i3g2000cwc.googlegroups.com>

Hi, I try to send ctrl+C to a pipe process to stop a program here rec
from sox to record. This is a example how I get the pipe going. When
you run this program you will record a wav file and pressing ctrl+c
will stop and it will start to record right away. If you need to have a
new file at a song break. I would like to have the program send the
crtl+C. So I could use any other event and change the event to be
ctrl+C.

 #!/usr/bin/perl

 use IO::Handle;
 #$pid = fork;
 #print "pid = $pid.\n";
 #if ($pid == 0) {
 # print "In child.\n";
 # $return_value = system ("rec testme.wav");
 # print "System returned $return_value\n";
 # exit(0);
 #}elsif (undef $pid) {
 #} else {

 $pid = open(SPOOLER, "|rec -c 2 -r 44100 testme.wav") ||
 die "can't fork: $!";
 local $SIG{PIPE} = sub { die "spooler pipe broke" };
 print "hi there\n";
 sleep(5);
 print SPOOLER "\cC \n";
 print "pid = $pid waited 5 sec\n";
 #SPOOLER->autoflush();
 #print "after autoflush\n";

 close SPOOLER || die "bad spool: $! $?";
 print "closed file testme.wav\n";
 open(SPOOLER, "|rec -c 2 -r 44100 testme1.wav") || die "can't
 fork: $!";
 local $SIG{PIPE} = sub { die "spooler pipe broke" };
 #print SPOOLER "$SIG{INT}";
 close SPOOLER || die "bad spool: $! $?";
 print "closed file testme1.wav\n";
 # $status = waitpid($pid,0);
 # print "Child is dead with $status.\n";
 #}

 I try it with the print option, but It doesn't work. How can I sent
 ctrl+C to the sox recording program through perl?
 
 Any Idea
 
 thanks
 guenter



------------------------------

Date: Sun, 15 Oct 2006 09:38:33 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: sending ctrl+C to pipe process
Message-Id: <m2hcy5g0me.fsf@Sherm-Pendleys-Computer.local>

"linbox" <gweissenseel@yahoo.com> writes:

> Hi, I try to send ctrl+C to a pipe process to stop a program here rec
> from sox to record. This is a example how I get the pipe going. When
> you run this program you will record a wav file and pressing ctrl+c
> will stop and it will start to record right away.

A *nix shell will normally handle Ctrl-C by sending a signal to the current
foreground process. So what you're actually asking is how to send that
signal from Perl.

Have a look at 'perldoc -f kill'.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: 15 Oct 2006 08:32:34 -0700
From: "linbox" <gweissenseel@yahoo.com>
Subject: Re: sending ctrl+C to pipe process
Message-Id: <1160926354.466184.270110@e3g2000cwe.googlegroups.com>


Sherm Pendley wrote:
> "linbox" <gweissenseel@yahoo.com> writes:
>
> > Hi, I try to send ctrl+C to a pipe process to stop a program here rec
> > from sox to record. This is a example how I get the pipe going. When
> > you run this program you will record a wav file and pressing ctrl+c
> > will stop and it will start to record right away.
>
> A *nix shell will normally handle Ctrl-C by sending a signal to the current
> foreground process. So what you're actually asking is how to send that
> signal from Perl.
>
> Have a look at 'perldoc -f kill'.
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net

the kill function is not quiet what works for me. I looked at the pid's
and the sox's pid do not match the child's pid. It is always 3 higher
(when I check with top that's what I get)

doing this (code below) does not kill the recording either. I must be
missing something?

#!/usr/bin/perl

    use English '-no_match_vars';
    my $sleep_count = 0;
    do {
        $pid = open(KID_TO_WRITE, "|-");
        unless (defined $pid) {
            warn "cannot fork: $!";
            die "bailing out" if $sleep_count++ > 6;
            sleep 10;
        }
    } until defined $pid;

    if ($pid) {  # parent
        print "parents pid = $pid \n";
        sleep(5);
        print KID_TO_WRITE "\cC\n";
        print "send ctrl C\n";
        sleep(2);
        close(KID_TO_WRITE) || warn "kid exited $?";
    } else {     # child
        ($EUID, $EGID) = ($UID, $GID); # suid progs only
        print "kids pid = $pid \n";
        open (FILE, "| rec -c 2 -r 44100 testme2.wav")
            || die "can't open /safe/file: $!";
        while (<STDIN>) {
            print FILE; # child's STDIN is parent's KID
        }
        exit;  # don't forget this
    }



------------------------------

Date: 15 Oct 2006 18:54:57 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: sending ctrl+C to pipe process
Message-Id: <4pfeg1FinsmmU1@news.dfncis.de>

linbox <gweissenseel@yahoo.com> wrote in comp.lang.perl.misc:
> 
> Sherm Pendley wrote:
> > "linbox" <gweissenseel@yahoo.com> writes:
> >
> > > Hi, I try to send ctrl+C to a pipe process to stop a program here rec
> > > from sox to record. This is a example how I get the pipe going. When
> > > you run this program you will record a wav file and pressing ctrl+c
> > > will stop and it will start to record right away.
> >
> > A *nix shell will normally handle Ctrl-C by sending a signal to the current
> > foreground process. So what you're actually asking is how to send that
> > signal from Perl.
> >
> > Have a look at 'perldoc -f kill'.
> >
> > sherm--
> >
> > --
> > Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> > Cocoa programming in Perl: http://camelbones.sourceforge.net
> 
> the kill function is not quiet what works for me.

How do you know?  Did you try it?  It is exactly what you must use
if you want to emulate the action of control-C on a program.

> I looked at the pid's
> and the sox's pid do not match the child's pid. It is always 3 higher
> (when I check with top that's what I get)

Sure, your code forks twice before it runs the "rec" program.  Once
explicitly with some aplomb, and then implicitly through the
use of 

    open (FILE, "| rec -c 2 -r 44100 testme2.wav")

So the pids are different.  The amount by which they differ is irrelevant.

> doing this (code below) does not kill the recording either. I must be
> missing something?

Your code doesn't try to use kill() to signal the process but looks
like a futile attempt to send "\cC" literally to its stdin.

This is not what happens when you press control-C.  Your shell
intercepts it and sends a signal (INT) to the current process.
The process reacts to the signal, it never sees any input in this
action.

Use just a plain fork to run "rec", then signal its pid with a SIGINT.
That should do the same thing as running "rec" from the command line
and pressing control-C.

Anno

[code left for reference]

> #!/usr/bin/perl
> 
>     use English '-no_match_vars';
>     my $sleep_count = 0;
>     do {
>         $pid = open(KID_TO_WRITE, "|-");
>         unless (defined $pid) {
>             warn "cannot fork: $!";
>             die "bailing out" if $sleep_count++ > 6;
>             sleep 10;
>         }
>     } until defined $pid;
> 
>     if ($pid) {  # parent
>         print "parents pid = $pid \n";
>         sleep(5);
>         print KID_TO_WRITE "\cC\n";
>         print "send ctrl C\n";
>         sleep(2);
>         close(KID_TO_WRITE) || warn "kid exited $?";
>     } else {     # child
>         ($EUID, $EGID) = ($UID, $GID); # suid progs only
>         print "kids pid = $pid \n";
>         open (FILE, "| rec -c 2 -r 44100 testme2.wav")
>             || die "can't open /safe/file: $!";
>         while (<STDIN>) {
>             print FILE; # child's STDIN is parent's KID
>         }
>         exit;  # don't forget this
>     }
> 




------------------------------

Date: Sun, 15 Oct 2006 20:14:20 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <wEwYg.14212$UG4.13326@newsread2.news.pas.earthlink.net>

On 10/14/2006 10:19 PM, theshowmecanuck wrote:
> Hi, I am the original poster... I just changed over to my Linux box and the
> identity on this news reader is different.  :-)
> 
> I thought this might be what was happening.  I am trying to find a way to
> read the file one line at a time.  The bill file will eventually grow to
> about 1.5 Gigabytes, so I don't want to keep going back to the beginning of
> the file as will make this file merge way too slow and inefficient.  I now
> know I can use seek() but would like to find something that will allow me
> to move the file pointer ahead one row at a time rather than by byte...
> kind of why I was trying Perl... to simplify and speed up development.
> Since these are fixed width format files, I can move the file pointer ahead
> the width of the row plus the newline.  However, I will have figure out the
> length of the record dynamically/programmatically as I don't want to have
> to recode anything if they add a couple of new fields to the end of the
> record. 
> 
> If you have any more suggestions please fire away and thanks for the quick
> answers.
> 
> Cheers,
> 
> BillR
> 
> 
> 

Please bottom-post in this newsgroup.

You can use the Tie::File module to do exactly what you want.

perldoc Tie::File
perldoc perltie    (if you want the background info.)


-- 
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9850
***************************************


home help back first fref pref prev next nref lref last post