Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

system($cmd) spawns infinitely

by kurt2439 (Sexton)
on Nov 20, 2011 at 22:27 UTC ( #939109=perlquestion: print w/replies, xml ) Need Help??
kurt2439 has asked for the wisdom of the Perl Monks concerning the following question:

I'm not looping at all, I'm just trying to run another perl script from my perl script. However my process list fills up with the command stored in "$check_env_cmd". The script being called works fine on it's own. I don't get it! Here are what I think are all the relevant parts of my calling script -- it just executes the command in system() hundreds,thousands of times!

my $check_env_cmd="/usr/bin/perl /home/jchase/programming/moodle_rooms +_sync/ --modules --blocks"; #Make sure that a few of the critical Moodle Tests pass before loading + new db my $result=system($check_env_cmd); if ($result){ print "Environment Check Passed\n"; }else{ print "Environment Check Failed\n"; exit 1; }

I've also tried using backticks instead of the system() function. Same result. I tried inputting the command straight into system() as well but no joy. I'm sure I'm doing something stupid but I don't understand what -- it seems pretty straightforward. Is there something funny about calling a perl command from a perl command?

Replies are listed 'Best First'.
Re: system($cmd) spawns infinitely
by Eliya (Vicar) on Nov 20, 2011 at 23:44 UTC

    There is nothing special about calling a perl script via system, so I'd wager the problem lies elsewhere, in the code or the circumstances not mentioned.

    Try to create a minimal but complete set of code samples and step-by-step instructions that would allow someone else to replicate the problem. In the process of doing so, you will maybe discover what the problem is. If not, post what you've come up with here.

Re: system($cmd) spawns infinitely
by davido (Archbishop) on Nov 21, 2011 at 00:47 UTC

    What does the code inside look like?


Re: system($cmd) spawns infinitely
by trizen (Hermit) on Nov 21, 2011 at 00:49 UTC
    Are you sure you're not doing something like this?
    print "Running: $$\n"; system "perl $0";
Re: system($cmd) spawns infinitely
by tospo (Hermit) on Nov 21, 2011 at 13:28 UTC
    and what does it print to the terminal? Do you get thousands of "Environment Check..." messages as well? If you do then you are in a loop, possibly in the code that calls this code (sub?)
Re: system($cmd) spawns infinitely
by wol (Hermit) on Nov 25, 2011 at 10:51 UTC
    This may be a bit like stating the obvious, but could you reassure me that the code that calls system() isn't a part of your script!

    One way to get into an infinite loop would be to have a script recursively call itself. Not that I'm speaking from bitter experience, of course...

    use JAPH;
    print JAPH::asString();

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://939109]
Approved by davido
Front-paged by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-10-19 06:06 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (251 votes). Check out past polls.