• Publicidad

Correr runant.pl varias veces automáticamente

Todo lo relacionado con lenguajes de programación distintos de Perl: PHP, Java, C++, Ruby, Python, etc.

Correr runant.pl varias veces automáticamente

Notapor dbustos » 2014-02-25 08:34 @398

Hola a todos.

Quiero correr un script (runant.pl) varias veces para lo que simplemente lo puse dentro de un while {}, pero una vez que lo corre una vez sale del loop y termina sin cumplir la condición del while. Entiendo que es básica la forma en que lo hice, pero también es básico mi conocimiento de Perl, ¡je,je!

¡Muchas a todos!

Esto es lo que escribí:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. use File::Copy;
  3.  
  4. my $n = 1;
  5.  
  6. while ( $n < 4 ) {
  7.     $oldlocation = "/home/bec/Documents/PINA-WSclient_03072013/proteins$n.input";
  8.     $newlocation = "/home/bec/Documents/PINA-WSclient_03072013/proteins.input";
  9.     copy( $oldlocation, $newlocation );
  10.  
  11.     my $debug = 1;
  12.     use strict;
  13.     my $HOME = $ENV{ANT_HOME};
  14.     if ( $HOME eq "" ) {
  15.         die "\n\nANT_HOME *MUST* be set!\n\n";
  16.     }
  17.  
  18.     my $JAVACMD = $ENV{JAVACMD};
  19.     $JAVACMD = "java" if $JAVACMD eq "";
  20.  
  21.     my $onnetware = 0;
  22.     if ( $^O eq "NetWare" ) {
  23.         $onnetware = 1;
  24.     }
  25.  
  26.     my $oncygwin = ( $^O eq "cygwin" );
  27.  
  28.     my $s = ":";
  29.     if (   ( $^O eq "MSWin32" )
  30.         || ( $^O eq "dos" )
  31.         || ( $^O eq "cygwin" )
  32.         || ( $onnetware == 1 ) ) {
  33.         $s = ";";
  34.     }
  35.  
  36.     my $localpath = "$HOME/lib/ant-launcher.jar";
  37.     my @ANT_OPTS  = split( " ", $ENV{ANT_OPTS} );
  38.     my @ANT_ARGS  = split( " ", $ENV{ANT_ARGS} );
  39.  
  40.     if ( $ENV{JIKESPATH} ne "" ) {
  41.         push @ANT_OPTS, "-Djikes.class.path=$ENV{JIKESPATH}";
  42.     }
  43.  
  44.     my @ARGS;
  45.     push @ARGS, @ANT_OPTS;
  46.  
  47.     my $CYGHOME = "";
  48.  
  49.     my $classpath = $ENV{CLASSPATH};
  50.     if ( $oncygwin == 1 ) {
  51.         $localpath = `cygpath --path --windows $localpath`;
  52.         chomp($localpath);
  53.         if ( !$classpath eq "" ) {
  54.             $classpath = `cygpath --path --windows "$classpath"`;
  55.             chomp($classpath);
  56.         }
  57.         $HOME = `cygpath --path --windows $HOME`;
  58.         chomp($HOME);
  59.         $CYGHOME = `cygpath --path --windows $ENV{HOME}`;
  60.         chomp($CYGHOME);
  61.     }
  62.     push @ARGS, "-classpath", "$localpath";
  63.     push @ARGS, "-Dant.home=$HOME";
  64.     if ( !$CYGHOME eq "" ) {
  65.         push @ARGS, "-Dcygwin.user.home=\"$CYGHOME\"";
  66.     }
  67.     push @ARGS, "org.apache.tools.ant.launch.Launcher", @ANT_ARGS;
  68.     push @ARGS, @ARGV;
  69.     if ( !$classpath eq "" ) {
  70.         if ( $onnetware == 1 ) {
  71.             push @ARGS, "-lib", "\$CLASSPATH";
  72.         }
  73.         else {
  74.             push @ARGS, "-lib", "$classpath";
  75.         }
  76.     }
  77.     print "\n $JAVACMD @ARGS\n\n" if ($debug);
  78.  
  79.     my $returnValue = system $JAVACMD, @ARGS;
  80.     if ( $returnValue eq 0 ) {
  81.         exit 0;
  82.     }
  83.     else {
  84.         exit 1;
  85.     }
  86.  
  87.     $n++;
  88. }
  89.  
Coloreado en 0.004 segundos, usando GeSHi 1.0.8.4
Última edición por explorer el 2014-02-25 15:36 @692, editado 1 vez en total
Razón: Formateado de código con Perltidy y poner marcas Perl
dbustos
Perlero nuevo
Perlero nuevo
 
Mensajes: 11
Registrado: 2011-12-21 10:07 @463

Publicidad

Re: Correr runant.pl varias veces automáticamente

Notapor Aceitunas » 2014-02-25 13:21 @598

Desde la línea 80 a la 85:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. if ($returnValue eq 0)
  2.     {
  3.     exit 0;
  4.     }
  5. else
  6.     {
  7.     exit 1;
  8.     }
  9.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4


:roll: :lol:
Voy a llegar hasta el final, voy a subir la velocidad - Migue Benítez.
Aceitunas
Perlero nuevo
Perlero nuevo
 
Mensajes: 117
Registrado: 2013-11-07 15:25 @684
Ubicación: Ciudad Real, España.

Re: correr runant.pl varias veces automaticamente

Notapor dbustos » 2014-02-25 13:33 @606

Si elimino el $n++ de la línea 87, entonces ¿cómo se repite 4 veces (hasta que se cumpla la condición n < 4?
dbustos
Perlero nuevo
Perlero nuevo
 
Mensajes: 11
Registrado: 2011-12-21 10:07 @463

Re: correr runant.pl varias veces automaticamente

Notapor Aceitunas » 2014-02-25 13:41 @612

El problema es que tu programa acaba en la línea 82 u 86 con exit.

Yo lo que haría en vez de hacer la chapuza del bucle sería hacer otro script que lo ejecute 4 veces, ejemplo:

Para Windows.
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. system("archivo.pl");
  2. system("archivo.pl");
  3. system("archivo.pl");
  4. system("archivo.pl");
  5.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4


Para Linux creo que sería así (no probado).
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. system("/usr/bin/perl archivo.pl");
  2. system("/usr/bin/perl archivo.pl");
  3. system("/usr/bin/perl archivo.pl");
  4. system("/usr/bin/perl archivo.pl");
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Voy a llegar hasta el final, voy a subir la velocidad - Migue Benítez.
Aceitunas
Perlero nuevo
Perlero nuevo
 
Mensajes: 117
Registrado: 2013-11-07 15:25 @684
Ubicación: Ciudad Real, España.

Re: Correr runant.pl varias veces automáticamente

Notapor dbustos » 2014-02-25 13:49 @617

El problema es que no serían solo 4 veces sino 250 y cada vez lee un input diferente (input1, input2, etc., así hasta 250).
dbustos
Perlero nuevo
Perlero nuevo
 
Mensajes: 11
Registrado: 2011-12-21 10:07 @463

Re: Correr runant.pl varias veces automáticamente

Notapor Aceitunas » 2014-02-25 14:07 @629

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. my $tope = <STDIN>;
  2. my $contador = 1;
  3.  
  4. while ($contador < $tope)
  5. {
  6.     system("archivo.pl");
  7.     $contador++;
  8. }
  9.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Voy a llegar hasta el final, voy a subir la velocidad - Migue Benítez.
Aceitunas
Perlero nuevo
Perlero nuevo
 
Mensajes: 117
Registrado: 2013-11-07 15:25 @684
Ubicación: Ciudad Real, España.

Re: Correr runant.pl varias veces automáticamente

Notapor explorer » 2014-02-25 16:46 @740

Yo cambiaría estas líneas
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1.     if ( $returnValue eq 0 ) {
  2.         exit 0;
  3.     }
  4.     else {
  5.         exit 1;
  6.     }
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
por estas otras:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1.     if ( $returnValue == 0 ) {
  2.         print "Ejecución correcta\n";
  3.     }
  4.     else {
  5.         print "Ejecución normal\n";
  6.     }
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Correr runant.pl varias veces automáticamente

Notapor dbustos » 2014-02-26 08:10 @382

¡Gracias!, ambas soluciones funcionan bien.
dbustos
Perlero nuevo
Perlero nuevo
 
Mensajes: 11
Registrado: 2011-12-21 10:07 @463


Volver a Programación en general

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 1 invitado

cron