Skip to content

Latest commit

 

History

History
151 lines (130 loc) · 3.84 KB

execbat.pas

File metadata and controls

151 lines (130 loc) · 3.84 KB
 
Nov 18, 2000
Nov 18, 2000
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{$A+,B+,D-,E+,F+,I+,L+,N-,O+,R-,S+,V-}
unit execbat;
interface
uses
crt, dos,
{rcg11172000 no overlay under Linux.}
{overlay,}
common,
myio;
var
wind:windowrec;
sx,sy:integer;
wascls,savtw:boolean;
savcurwind:integer;
procedure execbatch(var ok:boolean; showit:boolean;
bfn,tfn,dir,batline:astr; oklevel:integer);
procedure pexecbatch(showit:boolean; bfn,tfn,dir,batline:astr;
var retlevel:integer);
procedure shel(s:astr);
procedure shel1;
procedure shel2;
implementation
procedure execbatch(var ok:boolean; { result }
showit:boolean; { show working on user side }
bfn:astr; { .BAT filename }
tfn:astr; { temporary testing file }
dir:astr; { directory takes place in }
batline:astr; { .BAT file line to execute }
oklevel:integer); { DOS errorlevel for success }
var bfp:text;
odir,todev:astr;
i,rcode:integer;
begin
todev:=' >nul';
if ((showit) and (incom)) then
todev:=' >'+systat.remdevice+' <'+systat.remdevice
else
if (wantout) then todev:=''; {' >con';}
getdir(0,odir);
dir:=fexpand(dir);
while copy(dir,length(dir),1)='\' do dir:=copy(dir,1,length(dir)-1);
assign(bfp,bfn);
rewrite(bfp);
writeln(bfp,'echo off');
writeln(bfp,chr(exdrv(dir)+64)+':');
writeln(bfp,'cd '+dir);
writeln(bfp,batline+todev);
writeln(bfp,':done');
writeln(bfp,chr(exdrv(odir)+64)+':');
writeln(bfp,'cd '+odir);
writeln(bfp,'exit');
close(bfp);
if (wantout) then begin
tc(15); textbackground(1); clreol; write(batline); clreol;
tc(7); textbackground(0); writeln;
end;
{ if (todev=' >con') then todev:='' else todev:=' >nul';}
shelldos(FALSE,bfn+todev,rcode);
chdir(odir);
{$I-} erase(bfp); {$I+}
if (oklevel<>-1) then ok:=(rcode=oklevel) else ok:=TRUE;
end;
procedure pexecbatch(showit:boolean; { show working on user side }
bfn:astr; { .BAT filename }
tfn:astr; { UNUSED ----------- }
dir:astr; { directory takes place in }
batline:astr; { .BAT file line to execute }
var retlevel:integer); { DOS errorlevel returned }
var tfp,bfp:text;
odir,todev:astr;
begin
todev:=' >nul';
if (showit) and (incom) then
todev:=' >'+systat.remdevice+' <'+systat.remdevice
else
if (wantout) then todev:=' >con';
getdir(0,odir);
dir:=fexpand(dir);
while copy(dir,length(dir),1)='\' do dir:=copy(dir,1,length(dir)-1);
assign(bfp,bfn);
rewrite(bfp);
writeln(bfp,'echo off');
writeln(bfp,chr(exdrv(dir)+64)+':');
writeln(bfp,'cd '+dir);
writeln(bfp,batline+todev);
writeln(bfp,':done');
writeln(bfp,chr(exdrv(odir)+64)+':');
writeln(bfp,'cd '+odir);
writeln(bfp,'exit');
close(bfp);
if (wantout) then begin
tc(15); textbackground(1); clreol; write(batline); clreol;
tc(7); textbackground(0); writeln;
end;
if (todev=' >con') then todev:='' else todev:=' >nul';
shelldos(FALSE,bfn+todev,retlevel);
chdir(odir);
{$I-} erase(bfp); {$I+}
end;
procedure shel(s:astr);
begin
wascls:=FALSE;
savcurwind:=systat.curwindow;
if (s<>'') then begin
wascls:=TRUE;
sx:=wherex; sy:=wherey;
setwindow(wind,1,1,80,25,7,0,0);
clrscr;
textbackground(1); tc(15); clreol;
write(s);
textbackground(0); tc(7); writeln;
end else
if (savcurwind<>0) then sclearwindow;
{ if (not systat.istopwindow) then sclearwindow;}
end;
procedure shel1;
begin
shel('');
end;
procedure shel2;
begin
if (wascls) then begin
clrscr;
removewindow(wind);
gotoxy(sx,sy);
topscr;
end else
if (savcurwind<>0) then schangewindow(TRUE,savcurwind);
end;
end.