forked from vit-project/vit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.pl
65 lines (59 loc) · 1.46 KB
/
exec.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2012 - 2013, Steve Rader
# Copyright 2013 - 2016, Scott Kostyshak
sub task_exec {
my ($cmd) = @_;
my $es = 0;
my $result = '';
&audit("TASK EXEC $task $cmd 2>&1");
open(IN,"echo -e \"yes\\n\" | $task $cmd 2>&1 |");
while(<IN>) {
chop;
$_ =~ s/\x1b.*?m//g; # decolorize
if ( $_ =~ /^\w+ override:/ ) { next; }
$result .= "$_ ";
}
close(IN);
if ( $! ) {
$es = 1;
&audit("FAILED \"$task $cmd\" error closing short pipe");
}
if ( $? != 0 ) {
$es = $?;
&audit("FAILED \"$task $cmd\" returned exit status $?");
}
return ($es,$result);
}
#------------------------------------------------------------------
sub exited_successfully {
my $status = shift || 0;
return 1 if WIFEXITED($status) and WEXITSTATUS($status)==0;
return undef;
}
sub shell_exec {
my ($cmd,$mode) = @_;
endwin();
if ( $clear ne 'NOT_FOUND' ) { system("$clear"); }
if ( $audit ) {
print "$_[0]\r\n";
}
if ( ! fork() ) {
&audit("EXEC $cmd");
exec($cmd);
exit();
}
wait();
my $success = &exited_successfully($?);
# two reasons to wait:
# - an error occurred
# - $mode is wait and the user didn't specify nowait in config file
if ( not $success or ( $mode eq 'wait' and not $nowait ) or $mode eq 'forcewait' ) {
if (not $success) {
print "Error while executing command `$cmd'\n";
}
print "Press return to continue.\r\n";
<STDIN>;
}
&init_curses('refresh');
&draw_screen();
}
return 1;