CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Problem with Perl 'system' comand

 



barryk
New User


May 26, 2010, 7:41 AM

Post #1 of 6 (3992 views)
Problem with Perl 'system' comand Can't Post

At the office we run an AIX ver 5 rel 3 system. We have a Perl script that given its parameters makes a decision on how to call several other programs. One of the programs that it calls is a compiled C program. I was having problems so I investigated and found that an environment variable that is known to the Perl script is not received by the compiled C program. The Perl script uses the Perl 'system' function to run the compiled C program. According to the information I found for AIX the limit of parameters and environment variables is very large for our system, so that is not the problem.

Any ideas as to why an environment variable gets lost when the C program is called ?


shawnhcorey
Enthusiast


May 26, 2010, 9:33 AM

Post #2 of 6 (3988 views)
Re: [barryk] Problem with Perl 'system' comand [In reply to] Can't Post

Does the system command call it as a string or a list. As a string, it starts a shell, which may change the environment depending on the user. Normally, it uses the POSIX shell, sh(1).

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


rovf
Veteran

May 27, 2010, 8:31 AM

Post #3 of 6 (3978 views)
Re: [barryk] Problem with Perl 'system' comand [In reply to] Can't Post

This can't be. The enivironment is passed to the subprocesses.

Did you print $ENV{YOURVARIABLE} *right* before invoking system(), and also print getenv("YOURVARIABLE") just in the beginning of your main() function in the C program? I bet they don't disappear inbetween.


barryk
New User


May 27, 2010, 11:41 AM

Post #4 of 6 (3965 views)
Re: [barryk] Problem with Perl 'system' comand [In reply to] Can't Post

Thanks to all who replied to my posting. I have finally solved the problem. The problem was that I set the value of the environment variable from the command line, next I ran the Perl script which ran the compiled C program by passing a single string to system(). When system() fork'ed a shell to run the specified C program it read my $HOME/.kshrc file which contained another definition of the environment variable which ended up overwriting the value I had entered manually from the command line.


rovf
Veteran

May 28, 2010, 8:19 AM

Post #5 of 6 (3937 views)
Re: [barryk] Problem with Perl 'system' comand [In reply to] Can't Post

You should always unset $ENV{ENV} before shelling out to ksh...


rovf
Veteran

Jun 28, 2010, 2:51 AM

Post #6 of 6 (3324 views)
Re: [barryk] Problem with Perl 'system' comand [In reply to] Can't Post

I wonder why system() was calling ksh in your case. It is supposed to use Bourne Shell....

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives