Set environment variables and run programs in Perl

Source: Internet
Author: User
Tags perl script

Requirement: the Perl script controls the experiment process. Because different applications need to set different experiment environments, You need to reset the environment variables according to the input. Environment Variable initialization method: Source Env. SH and source henv. sh, the compilation command is $ compile, And the execution command is $ run. You must compile the execution program in the reset environment variable.

 

In a Perl script, the system call is implemented through the system, but the system is a separate process. Once it is returned, the environment it is created will be lost, therefore, a process derived from system needs to execute environment creation, compilation, and running at the same time (for how Perl cannot return environment variables to the parent process, see Appendix 1 ). Therefore, you must write the Perl Command in the following format:

System ("Source $ ENV. Sh & $ compile & $ Run ");

 

 

In addition, source is a shell embedded command, so direct calling is as follows:

System ("Source $ ENV. Sh ")

The above method does not really change the environment variables of the system dispatch process. You must add & or explicitly call the shell command. The correct method is as follows:

 

1) System ("Source $ ENV. Sh & which GCC"), because when the process cannot find the command source, it does not search for related commands for the first time, and the second time it will.

2) system ("/usr/bin/shell", "-c", "Source $ ENV. Sh ");

 

However, I have not found the method for executing multiple commands in 2). Does anyone know?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.