1 | if ( ! exists $ENV{'ENVI_HOME'} || ! exists $ARGV[0] ) {
|
---|
2 | die "please run 'envi', not 'rt.pl'\n";
|
---|
3 | }
|
---|
4 |
|
---|
5 | do "$ENV{'ENVI_HOME'}/lib/util.pl";
|
---|
6 |
|
---|
7 | my $task = $ARGV[0]; shift(@ARGV);
|
---|
8 | my $task_executable = task_location($task) . "/task.pl";
|
---|
9 | my $task_options = task_location($task) . "/options.txt";
|
---|
10 |
|
---|
11 | #set task home and name for the benefit of the task
|
---|
12 | $ENV{'TASK_HOME'} = task_location($task);
|
---|
13 | $ENV{'TASK_NAME'} = $task;
|
---|
14 |
|
---|
15 | #setup the task environment
|
---|
16 | if ( -f system_task_environment_script($task) ) {
|
---|
17 | envi_message( "getting $task system env");
|
---|
18 | my $v = system_task_environment_script($task);
|
---|
19 | do $v;
|
---|
20 | }
|
---|
21 | if ( -f user_task_environment_script($task) ) {
|
---|
22 | envi_message( "getting $task user env");
|
---|
23 | my $v = user_task_environment_script($task);
|
---|
24 | do $v;
|
---|
25 | }
|
---|
26 |
|
---|
27 | #do what they asked:
|
---|
28 | if ( $ARGV[0] eq "env" ) {
|
---|
29 |
|
---|
30 | shift(@ARGV);
|
---|
31 |
|
---|
32 | # - run something in the task environment
|
---|
33 | if ( exists $ARGV[0] ) {
|
---|
34 | my $command = $ARGV[0] . " ";
|
---|
35 | shift(@ARGV);
|
---|
36 | for my $a ( @ARGV ) {
|
---|
37 | $command .= " \"$a\"";
|
---|
38 | }
|
---|
39 | system( $command );
|
---|
40 |
|
---|
41 | # - show task environment
|
---|
42 | } else {
|
---|
43 | foreach my $key (keys %ENV) {
|
---|
44 | print "$key=$ENV{$key}\n";
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | # - show task options
|
---|
49 | } elsif ( $ARGV[0] eq "options" ) {
|
---|
50 | if ( -f "$task_options" ) {
|
---|
51 | open( FILE, "< $task_options" ) or die "Can't open $filename : $!";
|
---|
52 | while( <FILE> ) {
|
---|
53 | print;
|
---|
54 | }
|
---|
55 | close FILE;
|
---|
56 | }
|
---|
57 |
|
---|
58 | # - run the task
|
---|
59 | } else {
|
---|
60 | my $command = "perl \"$task_executable\"";
|
---|
61 | for my $a ( @ARGV ) {
|
---|
62 | $command .= " \"$a\"";
|
---|
63 | }
|
---|
64 |
|
---|
65 | envi_message( "task command: $command" );
|
---|
66 | system( $command );
|
---|
67 | }
|
---|