put dx.pl into an explicit handle sub
[spider.git] / perl / DXCron.pm
index e60d36b4ba8f02f934c2842a030c57cde11c4cfb..c011d7b3d3e3df0740bfbdc3662edd6646b95d30 100644 (file)
@@ -62,7 +62,7 @@ sub cread
        my $line = 0;
        my @out;
 
-       dbg("cron: reading $fn\n") if isdbg('cron');
+       dbg("DXCron::cread reading $fn\n") if isdbg('cron');
        open($fh, $fn) or confess("cron: can't open $fn $!");
        while (<$fh>) {
                $line++;
@@ -81,9 +81,9 @@ sub cread
                if (!$err) {
                        $ref->{cmd} = $cmd;
                        push @out, $ref;
-                       dbg("cron: adding $_\n") if isdbg('cron');
+                       dbg("DXCron::cread: adding $_\n") if isdbg('cron');
                } else {
-                       dbg("cron: error on line $line '$_'\n") if isdbg('cron');
+                       dbg("DXCron::cread: error on line $line '$_'\n") if isdbg('cron');
                }
        }
        close($fh);
@@ -246,10 +246,10 @@ sub spawn
 {
        my $line = shift;
 
+       dbg("DXCron::spawn: $line") if isdbg("cron");
        my $fc = Mojo::IOLoop::Subprocess->new();
        $fc->run(
                         sub {my @res = `$line`; return @res},
-#                       [],
                         sub {
                                 my ($fc, $err, @res) = @_; 
                                 if ($err) {
@@ -269,20 +269,24 @@ sub spawn_cmd
 {
        my $line = shift;
 
-       dbg("spawn_cmd run: $line") if isdbg('cron');
+       dbg("DXCron::spawn_cmd run: $line") if isdbg('cron');
        my $fc = Mojo::IOLoop::Subprocess->new();
        $fc->run(
-                        sub {my @res = DXCommandmode::run_cmd($main::me, $line); return @res},
-#                       [],
+                        sub {
+                                $main::me->{_nospawn} = 1;
+                                my @res = $main::me->run_cmd($line);
+                                delete $main::me->{_nospawn};
+                                return @res;
+                        },
                         sub {
                                 my ($fc, $err, @res) = @_; 
                                 if ($err) {
-                                        my $s = "spawn_cmd: error $err";
+                                        my $s = "DXCron::spawn_cmd: error $err";
                                         dbg($s);
                                 }
                                 for (@res) {
                                         chomp;
-                                        dbg("spawn_cmd: $_") if isdbg("cron");
+                                        dbg("DXCron::spawn_cmd: $_") if isdbg("cron");
                                 }
                         }
                        );
@@ -305,11 +309,11 @@ sub rcmd
 sub run_cmd
 {
        my $line = shift;
-       my @in = DXCommandmode::run_cmd($main::me, $line);
-       dbg("cmd run: $line") if isdbg('cron');
+       my @in = $main::me->run_cmd($line);
+       dbg("DXCron::run_cmd: $line") if isdbg('cron');
        for (@in) {
                s/\s*$//og;
-               dbg("cmd out: $_") if isdbg('cron');
+               dbg("DXCron::cmd out: $_") if isdbg('cron');
        }
 }