Re: PERL-POSTGRESQL

From: Bruno Unna <bruno(at)iac(dot)com(dot)mx>
To: JESUS AVILA MOLINA <avimolje(at)tuguri(dot)eupmt(dot)es>
Cc: Jose David Martinez Cuevas <david(at)morgana(dot)estadistica(dot)unam(dot)mx>, pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: Re: PERL-POSTGRESQL
Date: 1998-06-11 18:41:21
Message-ID: 358024D1.B922F71@iac.com.mx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

JESUS AVILA MOLINA wrote:
>
> Hola lista.
>
> Veras, me encuento con un pequenyo problema
> cuando intento trabajar con perl.
> Quiero ejecutar comandos de linux desde un CGI en perl
> pero no se como hacerlo. Los comandos serian un mkdir, cd..,
> mv, etc.
>
> Alguien podria hecharme un cable?
> Se lo agradeceria eternamente.
>
> Muchas gracias por adelantado.
>
> Jesus Avila.

Primero, te recomiendo que pruebes 'man perlfunc'. Ahí vienen
listadas las funciones a las que tienes acceso en Perl.

Ahora que si quieres hacer algo no soportado nativamente por
Perl, tienes 'system'.

Recortado de ahí:

mkdir FILENAME,MODE
Creates the directory specified by FILENAME, with
permissions specified
by MODE (as modified by umask). If it succeeds it
returns 1, otherwise
it returns 0 and sets $! (errno).

rename OLDNAME,NEWNAME
Changes the name of a file. Returns 1 for success, 0
otherwise. Will
not work across file system boundaries.

system LIST
Does exactly the same thing as "exec LIST" except that a
fork is done
first, and the parent process waits for the child process
to complete.
Note that argument processing varies depending on the
number of
arguments. The return value is the exit status of the
program as
returned by the wait() call. To get the actual exit
value divide by
256. See also the exec entry elsewhere in this document
. This is NOT
what you want to use to capture the output from a
command, for that you
should use merely backticks or qx//, as described in the
section on
`STRING` in the perlop manpage.

Because system() and backticks block SIGINT and SIGQUIT,
killing the
program they're running doesn't actually interrupt your
program.

@args = ("command", "arg1", "arg2");
system(@args) == 0
or die "system @args failed: $?"

Here's a more elaborate example of analysing the return
value from
system() on a Unix system to check for all possibilities,
including for
signals and core dumps.

$rc = 0xffff & system @args;
printf "system(%s) returned %#04x: ", "@args", $rc;
if ($rc == 0) {
print "ran with normal exit\n";
}
elsif ($rc == 0xff00) {
print "command failed: $!\n";
}
elsif ($rc > 0x80) {
$rc >>= 8;
print "ran with non-zero exit status $rc\n";
}
else {
print "ran with ";
if ($rc & 0x80) {
$rc &= ~0x80;
print "core dump from ";
}
print "signal $rc\n"
}
$ok = ($rc != 0);

When the arguments get executed via the system shell,
results will be
subject to its quirks and capabilities. See the section
on `STRING` in
the perlop manpage for details.

Suerte, saludos.
--
Bruno Unna <bruno(at)iac(dot)com(dot)mx>
Grupo Alta Calidad
ICQ UIN: 1858580
PGP public key available

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message CarlSerra 1998-06-12 17:20:43 Actualizacion automatica de datos
Previous Message JESUS AVILA MOLINA 1998-06-11 17:28:20 PERL-POSTGRESQL