2017-07-14 72 views
-1

我在需要调用另一个程序“b.pl”的终端上运行perl程序“a.pl”,然后将环境变为tcl shell。程序“b.pl”设置了我必须在主程序“a.pl”中使用的环境变量,之后我需要在由“b.pl”创建的tcl环境中运行新命令。请看下面的例子中父进程与子进程之间的通信 - Perl

程序:a.pl

#!/usr/intel/bin/perl -w 
    use strict; 
    use warnings; 

    #turns it to a tcl shell and sets environment variable VERSION 
    system ("./b.pl"); 

    system ("source <tclExecutable> -version $VERSION"); 

第二系统命令不执行,直到我在终端手动退出TCL壳。我已经看过叉子并打开一个管道,但我不知道该如何去做。我需要在第一个系统命令打开的tcl shell中执行第二个命令。我该如何做这项工作?

+1

你不能在一个子进程中设置的父的环境变量。 – choroba

+0

* b.pl如何设置env变量? –

+2

这是运行我见过的Tcl脚本的最奇怪的方式。好吧,无论如何,本周... –

回答

0

您可以使用require在“a.pl”内运行b.pl。它可以提供你想要的简单脚本。

a.pl

use strict; 
use warnings; 

our $Version; 
require "/.../b.pl"; # full path to b.pl script 
print "Version: $Version\n"; 

b.pl

use strict; 
use warnings; 

our $Version; 
$Version = "YES!";