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?