need simple beep and taint mode

Y

Yohan N. Leder

Very quick question this time. How to do a 'print "\a";' still produces
a beep when script is in taint mode. It works fine without -T, but
nothing in speaker when I'm back to taint mode. If it has some
importance, this test has been done using ActivePerl 5.8.8.817 under Win
2K. What's the trick ?
 
S

Sherm Pendley

Yohan N. Leder said:
Very quick question this time. How to do a 'print "\a";' still produces
a beep when script is in taint mode. It works fine without -T, but
nothing in speaker when I'm back to taint mode. If it has some
importance, this test has been done using ActivePerl 5.8.8.817 under Win
2K. What's the trick ?

How are you running your tests? Perl doesn't actually beep; 'print "\a";'
simply sends an ASCII control character to stdout. It's up to whatever's
collecting your script's output to decide how to respond to that character.

Quite a few terminals, for instance, have an option to invert the display
colors briefly instead of (or in addition to) beeping, for the hearing-
impaired.

So, are you running both tests in the same shell? Or does the silent one
happen to be running under something that's not likely to beep in response
to a "\a", such as a web server?

sherm--
 
A

anno4000

Yohan N. Leder said:
Very quick question this time.

If you don't know the answer, how do you know it's a "quick question"?
How to do a 'print "\a";' still produces
a beep when script is in taint mode. It works fine without -T, but
nothing in speaker when I'm back to taint mode. If it has some
importance, this test has been done using ActivePerl 5.8.8.817 under Win
2K. What's the trick ?

I can't reproduce your findings. If your diagnosis is indeed correct,
this looks like a rather messy problem.

Anno
 
B

Bart Van der Donck

Yohan said:
Very quick question this time. How to do a 'print "\a";' still produces
a beep when script is in taint mode. It works fine without -T, but
nothing in speaker when I'm back to taint mode. If it has some
importance, this test has been done using ActivePerl 5.8.8.817 under Win
2K.

Yes - I get a beep too under WinXP ActivePerl 5.8.4. This same beep can
be achieved by e.g. typing "echo", space, control-G and then Enter.
This should work in most/all terminals, as CTRL-G corresponds to
dec/hex 07 (BEL, bell, 0000111 in 7-bit ASCII) as the de-facto bell
signal.

The same would probably happen when displaying binaries in your
terminal, something like:

open my $F, '<', 'image.gif' || die "Cant open: $!";
print while(<$F>);
close $F || die "Cant close: $!";

My conclusion:
You can't know at Perl level whether or not the terminal will beep at
any character. It's just up to the shell. I would say this hasn't any
real importance too. Unless you want to program a singing shell or so
:)

Hope this helps,
 
B

Bart Van der Donck

Sherm said:
[...]
Perl doesn't actually beep; 'print "\a";' simply sends an ASCII control
character to stdout. It's up to whatever's collecting your script's output
to decide how to respond to that character.
[...]

Then you're actually saying that \a would be an alias to hex/dec 7 on
Yohan's terminal, because no other ASCII control character seems to
produce a beep on DOS-ish terminals:

#!perl

print "char $_ is ",chr($_),"\n" for (0..31);

=for nobody
ASCII CONTROL CHARACTERS
Dec Hex ASCII KEY
0 00 NUL (null) Ctrl-@
1 01 SOH (start of heading) Ctrl-A
2 02 STX (start of text) Ctrl-B
3 03 ETX (end of text) Ctrl-C
4 04 EOT (end of transmission) Ctrl-D
5 05 ENQ (enquiry) Ctrl-E
6 06 ACK (acknowledge) Ctrl-F
7 07 BEL (bell) Ctrl-G
8 08 BS (backspace) Ctrl-H
9 09 HT (horizontal tab) Ctrl-I
10 0A LF (line feed) Ctrl-J
11 0B VT (vertical tab) Ctrl-K
12 0C FF (form feed) Ctrl-L
13 0D CR (carriage return) Ctrl-M
14 0E SO (shift out) Ctrl-N
15 0F SI (shift in) Ctrl-O
16 10 DLE (data link escape) Ctrl-P
17 11 DC1 (device control 1) Ctrl-Q
18 12 DC2 (device control 2) Ctrl-R
19 13 DC3 (device control 3) Ctrl-S
20 14 DC4 (device control 4) Ctrl-T
21 15 NAK (negative acknowledge) Ctrl-U
22 16 SYN (synchronous idle) Ctrl-V
23 17 ETB (end of trans. block) Ctrl-W
24 18 CAN (cancel) Ctrl-X
25 19 EM (end of medium) Ctrl-Y
26 1A SUB (substitute) Ctrl-Z
27 1B ESC (escape) Ctrl-[
28 1C FS (file separator) Ctrl-\
29 1D GS (group separator) Ctrl-]
30 1E RS (record separator) Ctrl-^
31 1F US (unit separator) Ctrl-_
=cut

__END__

Maybe \a might be considered short for 'alarm' or 'alert'...

I might be wrong about this, but I rather think that \a doesn't refer
to an ASCII control character, but to a "somewhere far higher"
character. The fact that \a corresponds to a beep on some shells,
doesn't necessarily imply a relation to Hex 07.
 
A

anno4000

Bart Van der Donck said:
Sherm said:
[...]
Perl doesn't actually beep; 'print "\a";' simply sends an ASCII control
character to stdout. It's up to whatever's collecting your script's output
to decide how to respond to that character.
[...]

Then you're actually saying that \a would be an alias to hex/dec 7 on
Yohan's terminal, because no other ASCII control character seems to
produce a beep on DOS-ish terminals:

That is exactly what he's saying, and it's true too.

[snip]
Maybe \a might be considered short for 'alarm' or 'alert'...

Perl calls it "alarm (bell)" (see perlop). It's a backslash escape
like "\n" and many more.
I might be wrong about this,

You are, unnecessarily.
but I rather think that \a doesn't refer
to an ASCII control character, but to a "somewhere far higher"
character. The fact that \a corresponds to a beep on some shells,
doesn't necessarily imply a relation to Hex 07.

No seed to guess:

print "okay\n" if "\a" eq "\cG" and "\a" eq chr 7;

prints okay and removes all doubt.

Anno
 
B

Bart Van der Donck

Bart Van der Donck said:
[...]
but I rather think that \a doesn't refer
to an ASCII control character, but to a "somewhere far higher"
character. The fact that \a corresponds to a beep on some shells,
doesn't necessarily imply a relation to Hex 07.

No seed to guess:

print "okay\n" if "\a" eq "\cG" and "\a" eq chr 7;

prints okay and removes all doubt.

It does. I see.
 
Y

Yohan N. Leder

sherm@Sherm- said:
How are you running your tests? Perl doesn't actually beep; 'print "\a";'
simply sends an ASCII control character to stdout. It's up to whatever's
collecting your script's output to decide how to respond to that character.

Quite a few terminals, for instance, have an option to invert the display
colors briefly instead of (or in addition to) beeping, for the hearing-
impaired.

So, are you running both tests in the same shell? Or does the silent one
happen to be running under something that's not likely to beep in response
to a "\a", such as a web server?

sherm--

My test has been done in a DOS box under Win2K, running "perl beep.pl"
with beep.pl being :

#!/usr/bin/perl -w
use strict;
$|=1;
print "\a";
exit 0;

However, since I ran this script through a Win32::process::Create call,
I didn't seen that when "#!/usr/bin/perl -wT", it gives an error message
('-T is on the #! line, it must also be used on the command line at
beep.pl line 1') which does 'print "\a";' is never reached. So, running
"perl -T beep.pl" resolve the thing and beep is heard.

Nevertheless, because you talk about CGI orientation, it interest me too
to know how to produce a simple beep in internal speaker when script is
reached through web server and current STDOUT is a web browser. Do you
have an idea without using any external module ? Or, what's the module
that gives the best combination reliability-simplicity under both Unix
and Win ?
 
Y

Yohan N. Leder

Maybe \a might be considered short for 'alarm' or 'alert'...

I confirm that "print '\a';" produce a beep in DOS-box under Win2K as
replied to Sherm P. just above in this thread.

However, problem in taint mode was due to an error message which did the
print line was never reached : solved now !
 
Y

Yohan N. Leder

Perl calls it "alarm (bell)" (see perlop). It's a backslash escape
like "\n" and many more.

Effectively, I've tried too to run 'print "\a";' in the Komodo's
interactive Perl shell and it produces 'BEL' on screen rather than
something in speaker, confirming what you says.
 
Y

Yohan N. Leder

Yes - I get a beep too under WinXP ActivePerl 5.8.4. This same beep can
be achieved by e.g. typing "echo", space, control-G and then Enter.
This should work in most/all terminals, as CTRL-G corresponds to
dec/hex 07 (BEL, bell, 0000111 in 7-bit ASCII) as the de-facto bell
signal.

Effectively, I remember now that this CTRL-G is often used in DOS batch
listings.
My conclusion:
You can't know at Perl level whether or not the terminal will beep at
any character. It's just up to the shell. I would say this hasn't any
real importance too. Unless you want to program a singing shell or so

Oh no, the things was to indicate to an operator that a process is well
running, producing this beep a every turn in a big loop. Knowing, of
course, and here is the real reason that this 'human operator' is not in
front of the screen all the time and has to be alerted by something
resonant; whatever be the nature of the sound (a simpe beep is enough).

Also, and as I said to Sherm P. in this thread too, I'm interesting to
produce a sound (any sound) when the terminal is a web browser (in CGI
environment) : do you have an idea for this second and different case to
solve ?
 
A

anno4000

Yohan N. Leder said:
Because I said 'quick question' and not 'quick answer'.

Are you saying you wrote it to point out the obvious fact that the
question was short? I don't believe you.

Anno
 
B

Bart Van der Donck

Yohan said:
[..]
Oh no, the things was to indicate to an operator that a process is well
running, producing this beep a every turn in a big loop. Knowing, of
course, and here is the real reason that this 'human operator' is not in
front of the screen all the time and has to be alerted by something
resonant; whatever be the nature of the sound (a simpe beep is enough).

#!/perl
use strict;
use warnings;
$|++; # make sure to unbuffer output
print "Running 1 to 10...\n";
for (1..10) {
sleep 2;
print "\a$_ ";
}
print "\nend.";
Also, and as I said to Sherm P. in this thread too, I'm interesting to
produce a sound (any sound) when the terminal is a web browser (in CGI
environment) : do you have an idea for this second and different case to
solve ?

In that case you should instruct the browser to play an external sound
file, f.i. something like this (for Microsoft Internet Explorer only):

#!/usr/bin/perl
print "Content-Type: text/html; charset=iso-8859-1\n\n";
$|++; # make sure to unbuffer output
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
print '<html><body>
<iframe id="s" name="s"
src="http://www.dotinternet.be/temp/play.htm"
style="display:none; visibility:hidden;">
</iframe> Running 1 to 10...<br>';
for (1..10) {
sleep 2;
print '
<script type="text/javascript">
window.frames.s.location.href =
"http://www.dotinternet.be/temp/play.htm";
</script>
&nbsp; '.$_
}
print '<br>end.</body></html>';

It uses the following files:

http://www.dotinternet.be/temp/play.htm
http://www.dotinternet.be/temp/file.mp3

(P.S. Make sure to disable possible max runtime flags at Apache/CGI/OS
level, if any)

Hope this helps,
 
Y

Yohan N. Leder

Are you saying you wrote it to point out the obvious fact that the
question was short? I don't believe you.

Anno

Don't interprete, Anno. Here is my exact original sentence : "Very quick
question this time." All attempt to change any word is an
interpretation. Not a matter of believing, but reading only.
 
T

Tad McClellan

Yohan N Leder said:
However, problem in taint mode was due to an error message which did the
print line was never reached : solved now !


So your "quick question" was not so quick.

Why?

Because you were getting error messages that you did not mention.

Once again you display a lack of respect for your peers.

This is becoming tiresome in the extreme.
 
S

Sherm Pendley

Yohan N. Leder said:
Nevertheless, because you talk about CGI orientation, it interest me too
to know how to produce a simple beep in internal speaker when script is
reached through web server and current STDOUT is a web browser.

I think you mentioned earlier that you're writing an internal app on a LAN,
so I won't get into the wisdom(?) of noisy pages on the WWW. ;-\
have an idea without using any external module?

It depends on why you want the beep to happen. The simplest possible way
would be to print an <object> and/or <embed> that refers to a sound file.

If you want the beep to happen as the result of a specified server-side
event, you could place the above in a hidden frame, and use JavaScript or
a meta refresh to periodically update it from the server. Your CGI would
return an empty (i.e. silent) HTML block until the watched-for event
happens, then return the HTML that would load the sound.

Note that you won't achieve precise synronicity this way - there will
always be a variable-length delay between the time the beep is sent from
the server and the time it's played in the browser. But if all you need is
a "process finished" alarm of some sort, then even several seconds of lag
would probably be acceptable.

I've kept this intentionally brief, because big pieces of this would be
implemented in client-side JS and HTML, which are off-topic in this group.

sherm--
 
A

anno4000

Yohan N. Leder said:
Don't interprete, Anno. Here is my exact original sentence : "Very quick
question this time."

Reading *is* interpretation -- if that basic fact has escaped you your
world view is simplistic indeed.
All attempt to change any word is an
interpretation. Not a matter of believing, but reading only.

My interpretation is based on the half-dozen or so questions per week
we get here that are announced as "quick", "easy", "simple", and so forth.
It's a stereotype that invariably aims at attracting more attempts to
answer the question. In the long run, that gets annoying. Yours was
no different from any other of its kind.

Anno
 
S

Sherm Pendley

My interpretation is based on the half-dozen or so questions per week
we get here that are announced as "quick", "easy", "simple", and so forth.

Heh. That's not limited to this group. How many times has your boss asked
you for a "quick little app" that wound up taking days to finish?

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top