magic_yang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm new here and a perl novice.

I've a perl script where I use the system() command in a loop. Through the first couple loop iterations, the system() command is successful. Eventually, however, all system() commands fail to work.

Notes on setup: I'm running perl 5.8.5 on a lin64 machine.

Things I've tried:
(1) Printing out the line (because it contains variables). It prints exactly how I desire it to. I even run the printed string independently on my system and it works fine.
(2) Using backticks. The first missed system() complains about a missing file, but the file is there and permissions are set properly. Again, if I run the string outside of the perl script, everything works fine.

My thought is that there are limitations to the system() command that I don't know about. Been stuck on this for about a week. Would appreciate any feedback you guys can offer

Replies are listed 'Best First'.
Re: Any limitations to system() command?
by Fletch (Bishop) on Feb 27, 2006 at 19:49 UTC

    You need to go into a bit more detail than "fail to work". What error message(s) are you getting? Does what gets run fork off any persistent children (i.e. could you possibly be hitting up against either a per-user or machine wide process limit)? Are you running this in a non-shell environment (e.g. from cron or as a CGI)?

    See also How (Not) To Ask A Question.

      I don't think it forks off any persistent children. I've my main script, it executes a child process, and regains control after the process is done executing. So, there should only one active child process at a time.

      I'm running this in tcsh.

      I don't get any error messages. The script just continues on, but I know there's a problem because the file the system() command was supposed to generate doesn't appear.

      Anyway I can capture the errors? Sorry, I'm way noob. Please be patient with me
Re: Any limitations to system() command?
by liverpole (Monsignor) on Feb 27, 2006 at 20:51 UTC
    I think you'll need to post your code, if that's possible.  Otherwise, there are so many reasons it could be failing.  Is it small enough of a program that you can post it here?  If not, can you trim it down in size to the point that you can?

    In the absence of seeing what you've written, there are a few things which come to mind:

    • Are you running out of processes somehow?  Check with ps
    • Is the system command failing at some point?  Check by printing out the exit value from the system call; it's saved to the special variable $?.  In fact, if you haven't done so already, try reading about the system function with:  perldoc -i system.
    • Are you able to "run the string outside of the perl script" even after it has started failing from within Perl?  

    But these are just thoughts ... I think once you post an actual example of the code, and especially if it's something that can be duplicated by one of the others here, you'll likely be pleased with how quickly we can help you detect the problem.


    @ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
      Liverpole,

      I forgot about perldoc, as I usually use the o'reilly book. Learned about the $! variable that way.

      It turns out my problem was a memory allocation error. I'm using one of my company's proprietary modules. Turns out every version except the latest release had a bug in it that would act as a memory sink. Finally tracked down one of the developers and he let me in on the joke.

      Thanks for your help. I mainly work on IC's, and software's not my forte. Was stuck for a while and just had no idea how to proceed. I appreciate your assistance
Re: Any limitations to system() command?
by spiritway (Vicar) on Feb 28, 2006 at 01:19 UTC

    To expand on what [id://Fletch] and [id://liverpole] have said, you should try to post the offending code here. However, before you do that, you really need to read How (Not) To Ask A Question, as it will help you avoid common mistakes that could result in unhelpful answers. Avoid painful lumps and bruises. Read How (Not) To Ask A Question.

    I suggest that you pare down your code until it is the shortest possible script, yet still shows the error. If you haven't seen the answer then, go ahead and post the code here. In my experience (and many others here), the simple act of digging out the wayward code is enough to show you the error. Often it's obvious, but lost among all the other stuff going on.

    And when you do post the code, use code tags: '<c>' and '</c>'. This will allow you to format the code so that it displays well, something your fellow monks will appreciate.

      Maybe I wasn't clear, but $! solved the problem for me. Again, it was a memory allocation error.

      I would have posted the code if I thought it would've helped. But I was essentially looping on a print `$foo` command where $foo was a command execute proprietary software. Furthermore, that command worked for 12 cycles and also worked when I ran it outside of the script so I didn't think it was a syntax problem. I was just looking for more info on the nuances of running system() and commands through backticks. I did read How (Not) To Ask a Question, too.

      Anyways, it's been fun. Back to the world of hardware for me.