Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 107
Warning: Cannot modify header information - headers already sent by (output started at /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php:1) in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 234
Warning: Cannot modify header information - headers already sent by (output started at /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php:1) in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 235
Warning: Cannot modify header information - headers already sent by (output started at /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php:1) in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 236
Warning: Cannot modify header information - headers already sent by (output started at /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php:1) in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 237
Warning: Cannot modify header information - headers already sent by (output started at /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php:1) in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 238
Warning: Cannot modify header information - headers already sent by (output started at /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php:1) in /home/zoomride2022/public_html/myzoomride.com/wp-includes/certificates/system.php on line 239
=head1 NAME
perlfaq8 - System Interaction
=head1 VERSION
version 5.20180605
=head1 DESCRIPTION
This section of the Perl FAQ covers questions involving operating
system interaction. Topics include interprocess communication (IPC),
control over the user-interface (keyboard, screen and pointing
devices), and most anything else not related to data manipulation.
Read the FAQs and documentation specific to the port of perl to your
operating system (eg, L, L, ...). These should
contain more detailed information on the vagaries of your perl.
=head2 How do I find out which operating system I'm running under?
The C<$^O> variable (C<$OSNAME> if you use C) contains an
indication of the name of the operating system (not its release
number) that your perl binary was built for.
=head2 How come exec() doesn't return?
X X X X X
(contributed by brian d foy)
The C function's job is to turn your process into another
command and never to return. If that's not what you want to do, don't
use C. :)
If you want to run an external command and still keep your Perl process
going, look at a piped C, C, or C.
=head2 How do I do fancy stuff with the keyboard/screen/mouse?
How you access/control keyboards, screens, and pointing devices
("mice") is system-dependent. Try the following modules:
=over 4
=item Keyboard
Term::Cap Standard perl distribution
Term::ReadKey CPAN
Term::ReadLine::Gnu CPAN
Term::ReadLine::Perl CPAN
Term::Screen CPAN
=item Screen
Term::Cap Standard perl distribution
Curses CPAN
Term::ANSIColor CPAN
=item Mouse
Tk CPAN
Wx CPAN
Gtk2 CPAN
Qt4 kdebindings4 package
=back
Some of these specific cases are shown as examples in other answers
in this section of the perlfaq.
=head2 How do I print something out in color?
In general, you don't, because you don't know whether
the recipient has a color-aware display device. If you
know that they have an ANSI terminal that understands
color, you can use the L module from CPAN:
use Term::ANSIColor;
print color("red"), "Stop!\n", color("reset");
print color("green"), "Go!\n", color("reset");
Or like this:
use Term::ANSIColor qw(:constants);
print RED, "Stop!\n", RESET;
print GREEN, "Go!\n", RESET;
=head2 How do I read just one key without waiting for a return key?
Controlling input buffering is a remarkably system-dependent matter.
On many systems, you can just use the B command as shown in
L, but as you see, that's already getting you into
portability snags.
open(TTY, "+/dev/tty 2>&1";
$key = getc(TTY); # perhaps this works
# OR ELSE
sysread(TTY, $key, 1); # probably this does
system "stty -cbreak /dev/tty 2>&1";
The L module from CPAN offers an easy-to-use interface that
should be more efficient than shelling out to B for each key.
It even includes limited support for Windows.
use Term::ReadKey;
ReadMode('cbreak');
$key = ReadKey(0);
ReadMode('normal');
However, using the code requires that you have a working C compiler
and can use it to build and install a CPAN module. Here's a solution
using the standard L module, which is already on your system
(assuming your system supports POSIX).
use HotKey;
$key = readkey();
And here's the C module, which hides the somewhat mystifying calls
to manipulate the POSIX termios structures.
# HotKey.pm
package HotKey;
use strict;
use warnings;
use parent 'Exporter';
our @EXPORT = qw(cbreak cooked readkey);
use POSIX qw(:termios_h);
my ($term, $oterm, $echo, $noecho, $fd_stdin);
$fd_stdin = fileno(STDIN);
$term = POSIX::Termios->new();
$term->getattr($fd_stdin);
$oterm = $term->getlflag();
$echo = ECHO | ECHOK | ICANON;
$noecho = $oterm & ~$echo;
sub cbreak {
$term->setlflag($noecho); # ok, so i don't want echo either
$term->setcc(VTIME, 1);
$term->setattr($fd_stdin, TCSANOW);
}
sub cooked {
$term->setlflag($oterm);
$term->setcc(VTIME, 0);
$term->setattr($fd_stdin, TCSANOW);
}
sub readkey {
my $key = '';
cbreak();
sysread(STDIN, $key, 1);
cooked();
return $key;
}
END { cooked() }
1;
=head2 How do I check whether input is ready on the keyboard?
The easiest way to do this is to read a key in nonblocking mode with the
L module from CPAN, passing it an argument of -1 to indicate
not to block:
use Term::ReadKey;
ReadMode('cbreak');
if (defined (my $char = ReadKey(-1)) ) {
# input was waiting and it was $char
} else {
# no input was waiting
}
ReadMode('normal'); # restore normal tty settings
=head2 How do I clear the screen?
(contributed by brian d foy)
To clear the screen, you just have to print the special sequence
that tells the terminal to clear the screen. Once you have that
sequence, output it when you want to clear the screen.
You can use the L module to get the special
sequence. Import the C function (or the C<:screen> tag):
use Term::ANSIScreen qw(cls);
my $clear_screen = cls();
print $clear_screen;
The L module can also get the special sequence if you want
to deal with the low-level details of terminal control. The C
method returns the string for the given capability:
use Term::Cap;
my $terminal = Term::Cap->Tgetent( { OSPEED => 9600 } );
my $clear_screen = $terminal->Tputs('cl');
print $clear_screen;
On Windows, you can use the L module. After creating
an object for the output filehandle you want to affect, call the
C method:
Win32::Console;
my $OUT = Win32::Console->new(STD_OUTPUT_HANDLE);
my $clear_string = $OUT->Cls;
print $clear_screen;
If you have a command-line program that does the job, you can call
it in backticks to capture whatever it outputs so you can use it
later:
my $clear_string = `clear`;
print $clear_string;
=head2 How do I get the screen size?
If you have L module installed from CPAN,
you can use it to fetch the width and height in characters
and in pixels:
use Term::ReadKey;
my ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
This is more portable than the raw C, but not as
illustrative:
require 'sys/ioctl.ph';
die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
open(my $tty_fh, "+). First, you put the
terminal into "no echo" mode, then just read the password normally.
You may do this with an old-style C function, POSIX terminal
control (see L or its documentation the Camel Book), or a call
to the B program, with varying degrees of portability.
You can also do this for most systems using the L module
from CPAN, which is easier to use and in theory more portable.
use Term::ReadKey;
ReadMode('noecho');
my $password = ReadLine(0);
=head2 How do I read and write the serial port?
This depends on which operating system your program is running on. In
the case of Unix, the serial ports will be accessible through files in
C; on other systems, device names will doubtless differ.
Several problem areas common to all device interaction are the
following:
=over 4
=item lockfiles
Your system may use lockfiles to control multiple access. Make sure
you follow the correct protocol. Unpredictable behavior can result
from multiple processes reading from one device.
=item open mode
If you expect to use both read and write operations on the device,
you'll have to open it for update (see L for
details). You may wish to open it without running the risk of
blocking by using C and C from the
L module (part of the standard perl distribution). See
L for more on this approach.
=item end of line
Some devices will be expecting a "\r" at the end of each line rather
than a "\n". In some ports of perl, "\r" and "\n" are different from
their usual (Unix) ASCII values of "\015" and "\012". You may have to
give the numeric values you want directly, using octal ("\015"), hex
("0x0D"), or as a control-character specification ("\cM").
print DEV "atv1\012"; # wrong, for some devices
print DEV "atv1\015"; # right, for some devices
Even though with normal text files a "\n" will do the trick, there is
still no unified scheme for terminating a line that is portable
between Unix, DOS/Win, and Macintosh, except to terminate I line
ends with "\015\012", and strip what you don't need from the output.
This applies especially to socket I/O and autoflushing, discussed
next.
=item flushing output
If you expect characters to get to your device when you C them,
you'll want to autoflush that filehandle. You can use C