in reply to Can't locate vars.pm ... sometimes

Since you are generating and running the Perl script from inside the C program, the problem is likely in how you are running Perl from the C program. It is quite possible that environment is wrong. Check the PATH and PERL5LIB. Check which Perl is being used. It is possible that there is an old perl version installed which is getting run instead of the one you expect.

Why can't you pull the Perl code out of the C program? Put the Perl code in its own file. Then have the C program call the script with the arguments it needs. Much simpler, and you can debug or use the Perl script outside of the C program.

Replies are listed 'Best First'.
Re^2: Can't locate vars.pm ... sometimes
by gri6507 (Deacon) on Jun 24, 2004 at 18:16 UTC
    That is actually what the code does. The perl code is generated by the C, then sprintf(cmd,"perl perlfile.pl"); system(cmd);.Also, like I said earlier, it is just ONE process that is both successful and unsuccessful at the same time. Since the process is started, the environment is not changing, so I don't see how that could have any effect on anything.
      I meant don't generate the Perl code from the C code. Save the perl script in a file, put it some place where it can be run, and run it with a similar command line but passing the username or password as arguments. This will make it much easier to maintain and test the Perl script.

      Is the C process continually running and it sometimes fails in the same execution of the C process? Is there anywhere else in the code where the C program gets forked, or changes the environment?

      Do you have multiple perl installations? Is there any possibility it could be running different ones if the PATH changes? It is suspicious that there are two different sets of directories in the library list. Try specifying the full path to the perl program you want to use.

      Other things to try are printing out the command before running. Save the perl scripts and try running them manually with different environments. Compare the perl scripts to see if they are different for failing and successful execution. Print out the environment before running the command.