in reply to conditional calling of script from other script

can we have some more information to properly diagnose a solution?

1. is script1.pl going to be run once, then just loop; and you just want script2.pl to run the first iteration?

2. is there some external factor you could check for to see if script2.pl needs to be run? for instance, if it creates or modifies a file

if its only being run once at the start, perhaps just running it manually would be more efficient

- Justin
  • Comment on Re: conditional calling of script from other script

Replies are listed 'Best First'.
Re^2: conditional calling of script from other script
by sachin_chat (Initiate) on Feb 04, 2005 at 05:32 UTC
    1. i want my script1.pl to be executed any number of times. by executing the command # perl $PATH/script1.pl -qx . when this is executed for first time i will then execute script2.pl .now when i execute my script script1.pl second time or more number of times from same command as above. 2. i have to use some external factor to see if the script2.pl needs to be executed but i am unable to decide and that the main i am asking you all. i think this may give you some good idea of what i am asking.

      First of all, to answer your question directly, just have script1 check for the existence of a particular file; if that file doesn't exist, create it and run script2:

      my $LOCKFILE = 'script1.lock'; if (!-e $LOCKFILE) { open FH, ">$LOCKFILE" or die $!; close FH; system("perl script2.pl"); }

      However, if they're both perl scripts, it seems silly to do a fork and invoke another perl interpreter to run it. Can't you just use or require it and call whatever function(s) you need directly?

      -b

      sachin,

      Can you provide us with some code as to what these two scripts do? Thanks.

      Justin