-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec-program.html
executable file
·331 lines (301 loc) · 14.3 KB
/
exec-program.html
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!DOCTYPE html>
<html lang="en">
<head>
<!--__GOLF_REDIRECT__-->
<title>Exec program</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="HandheldFriendly" content="True"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="canonical" href="https://golf-lang.com/exec-program.html" />
<style>
body, html {
color:black;
text-rendering: optimizelegibility;
background-color: white;
min-height: 150%;
font-family: "Times New Roman";
font-weight:400;
font-size:18px;
line-height:27px;
letter-spacing: 2px;
z-index: 1;
height: 100%;
text-align:left;
width:80%;
margin-left:auto;
margin-right:auto;
padding:0;
/*font-family: Helvetica, Arial, sans-serif;*/
}
body {
padding-left:1vw;
padding-right:1vw;
}
.ncode {
line-height:20px;
letter-spacing: 0px;
font-size:14px;
font-family: monospace;
display:inline-block;
max-width:100%;
min-width:90%;
margin:0;
padding:0;
padding-left:5px;
padding-top:3px;
padding-bottom:3px;
margin-bottom:15px;
border: 2px solid #d6d6d6;
background-color:#f5f7f4;
white-space:nowrap;
}
.shcode {
line-height:23px;
letter-spacing: 0px;
font-size:14px;
font-family: monospace;
display:inline-block;
max-width:100%;
min-width:90%;
margin:0;
padding:0;
padding-left:5px;
padding-top:3px;
padding-bottom:3px;
margin-bottom:15px;
border: 2px solid #d6d6d6;
background-color:#f5f7f4;
white-space:nowrap;
}
.sqlcode {
line-height:23px;
letter-spacing: 0px;
font-size:14px;
font-family: monospace;
display:inline-block;
max-width:100%;
min-width:90%;
margin:0;
padding:0;
padding-left:5px;
padding-top:3px;
padding-bottom:3px;
margin-bottom:15px;
border: 2px solid #d6d6d6;
background-color:#f5f7f4;
white-space:nowrap;
}
.htmlcode {
line-height:23px;
letter-spacing: 0px;
font-size:14px;
font-family: monospace;
display:inline-block;
max-width:100%;
min-width:90%;
margin:0;
padding:0;
padding-left:5px;
padding-top:3px;
padding-bottom:3px;
margin-bottom:15px;
border: 2px solid #d6d6d6;
background-color:#f5f7f4;
white-space:nowrap;
}
.code {
line-height:23px;
letter-spacing: 0px;
font-size:14px;
font-family: monospace;
display:inline-block;
max-width:100%;
min-width:90%;
margin:0;
padding:0;
padding-left:5px;
padding-top:3px;
padding-bottom:3px;
margin-bottom:15px;
border: 2px solid #d6d6d6;
background-color:#f5f7f4;
white-space:nowrap;
}
/*Just like h1 but for pdf conversion it would be indented this way it's not*/
.vhub {
display: block;
font-size: 1.6em;
margin-top: 0.63em;
margin-bottom: 0.63em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
/*Just like h2 but for pdf conversion it would be indented this way it's not*/
.vsub {
display: block;
font-size: 1.25em;
margin-top: 0.53em;
margin-bottom: 0.53em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
ul {
margin-left: 0.75vw;
padding-left: 0;
}
li {
margin-left: 0.75vw;
padding-left: 0;
}
/* this must be last, as it overrides previous settings, for mobile */
@media (hover: none) {
a {
display: inline-block;
padding-top: 3px;
padding-bottom: 2px;
}
body {
padding-left:2vw;
padding-right:2vw;
font-size:14px;
line-height:22px;
letter-spacing: 1px;
}
}
/*The following is for code snippets that are highlighted by 2html vim*/
pre { overflow-x: scroll; margin:0; padding:0; font-family:monospace; }
.Identifier { color: #008b8b; }
.Statement { color: #af5f00; }
.PreProc { color: #5fd7ff; }
.Type { color: #005f00; }
.Comment { color: blue ; }
.Constant { color: #ff00ff; }
/*end of highlighted snippets*/
a {
text-decoration:none;
padding-bottom: 0px;
color:inherit;
border-bottom: 2px solid #6cb8f0;
}
a:hover {
text-decoration: none;
color:black;
border-bottom: 1px solid red;
}
/*do not underline links nor should they be active*/
pre a {
text-decoration:none;
color:black;
border-bottom: none;
pointer-events: none;
cursor: default;
}
.golfSnippet {display:none;}
ul {
list-style-type:square;
list-style-position: outside;
}
</style>
</head>
<body>
<script>
function gg_copy(gt, eid, gc) {
gt.textContent = eid.textContent;
gt.select();
document.execCommand("copy");
gc.style.visibility="visible"
setTimeout(()=>{ gc.style.visibility="hidden"; }, 1000);
}
</script>
<!--GOLFMENU13-->
<!--GOLFENDMENU13-->
<!--BEGVDOC90-->
<div class='vhub' style='margin-top:10px;margin-right:20px;text-align:right;background-color:white;'><a href='https://golf-lang.com' style='border-bottom:0px'><img src='https://golf-lang.com/golf.png'/></a></div><div class='vhub' style='margin-top:10px;'> Exec program</div><hr/><span style="font-weight:bold;">Purpose</span>: Execute a program.<br/>
<br/>
<div class='code' style='position:relative;padding-right:16px;'>
<pre id='code_447'>
<span class="Statement"> exec-program</span> <program path> \
[<span class="Identifier"> args</span> <program arg> [ , ... ] ] \
[<span class="Type"> status</span> <exit status> ] \
[ (<span class="Identifier"> input</span> <input string> [<span class="Identifier"> input-length</span> <string length> ] ) \
| (<span class="Identifier"> input-file</span> <input file> ) ] \
[ (<span class="Type"> output</span> <output string> ) \
| (<span class="Identifier"> output-file</span> <output file> ) ] \
[ (<span class="Type"> error</span> <error string> ) | (<span class="Identifier"> error-file</span> <error file> ) ]</pre>
<span id=golf_copied_447 style='position:absolute;right:-14px;top:-30px; cursor: pointer;visibility:hidden;background:white;'>Copied!</span>
<textarea id='golft_447' style='position: absolute;left: -500%;'></textarea>
<img src='https://golf-lang.com/golf-copy-small-1.png' id='golfb' onclick='gg_copy(golft_447, code_447, golf_copied_447)' style='position:absolute;right:0;top:0; cursor: pointer;opacity:0.5;'/>
</div><br/>
exec-program executes a program specified in <program path>, which can be a program name without path that exists in the path specified by the PATH environment variable; or an absolute path; or a path relative to the application home directory (see <a href='https://golf-lang.com/directories.html'>directories</a>).<br/>
<br/>
A program can have input arguments (specified as strings with "args" clause), and if there are more than one, they must be separated by a comma. There is no limit on the number of input arguments, other than of the underlying Operating System. <br/>
<br/>
You can specify a status variable <exit status> - this variable will have program's exit status. Note that if the program was terminated by a signal, <exit status> will have a value of 128+signal_number, so for example if the program was terminated with signal 9 (i.e. KILL signal), <exit status> will be 137 (i.e. 128+9). Any other kind of abnormal program termination (i.e. program termination where program did not set the exit code) will return 126 as <exit code>.<br/>
<br/>
Specifying program input and output is optional. If program has output and you are not capturing it in any way, the output is redirected to a temporary file that is deleted after exec-program completes.<br/>
<br/>
You can specify an <input string> to be passed to program's standard input (stdin) via "input" clause. If "input-length" is not used, the length of this input is the string length of <input string>, otherwise <string length> bytes is passed to the program. Alternatively, you can specify a file <input file> (via "input-file" clause) to be opened and directed into program's standard input (stdin). <br/>
<br/>
You can redirect the program's output (which is "stdout") to a file <output file> using "output-file" clause. Alternatively, program's output can be captured in <output string> (via "output" clause).<br/>
<br/>
To get the program's error output (which is "stderr") to file <error file>, use "error-file" clause. Alternatively, program's error output can be captured in <error string> (via "error" clause).<br/>
<br/>
If <input file> cannot be opened, GG_ERR_READ is reported in <exit status>, and if either <output file> or <error file> cannot be opened, the status is GG_ERR_WRITE.<br/>
<div class="vsub"><a id="Examples"></a>Examples</div>
To simply execute a program that is in the path, without any arguments, input or output:<br/>
<div class='code' style='position:relative;padding-right:16px;'>
<pre id='code_448'>
<span class="Statement"> exec-program</span> <span class="Constant">"myprogram"</span></pre>
<span id=golf_copied_448 style='position:absolute;right:-14px;top:-30px; cursor: pointer;visibility:hidden;background:white;'>Copied!</span>
<textarea id='golft_448' style='position: absolute;left: -500%;'></textarea>
<img src='https://golf-lang.com/golf-copy-small-1.png' id='golfb' onclick='gg_copy(golft_448, code_448, golf_copied_448)' style='position:absolute;right:0;top:0; cursor: pointer;opacity:0.5;'/>
</div><br/>
Run "grep" program using a string as its standard input in order to remove a line that contains "bad line" in it, and outputting the result into "ovar" variable:<br/>
<div class='code' style='position:relative;padding-right:16px;'>
<pre id='code_449'>
<span class="Statement"> exec-program</span> <span class="Constant">"grep"</span><span class="Identifier"> args</span> <span class="Constant">"-v"</span>, <span class="Constant">"bad line"</span> <span class="Constant">"config"</span><span class="Identifier"> input</span> <span class="Constant">"line 1</span><span class="Special">\n</span><span class="Constant">line 2</span><span class="Special">\n</span><span class="Constant">bad line</span><span class="Special">\n</span><span class="Constant">line 3"</span><span class="Type"> output</span> ovar
<span class="Statement"> p-out</span> ovar</pre>
<span id=golf_copied_449 style='position:absolute;right:-14px;top:-30px; cursor: pointer;visibility:hidden;background:white;'>Copied!</span>
<textarea id='golft_449' style='position: absolute;left: -500%;'></textarea>
<img src='https://golf-lang.com/golf-copy-small-1.png' id='golfb' onclick='gg_copy(golft_449, code_449, golf_copied_449)' style='position:absolute;right:0;top:0; cursor: pointer;opacity:0.5;'/>
</div><br/>
Get the list of files in the application home directory into buffer "ovar" and then display it:<br/>
<div class='code' style='position:relative;padding-right:16px;'>
<pre id='code_450'>
<span class="Statement"> exec-program</span> <span class="Constant">"ls"</span><span class="Type"> output</span> ovar</pre>
<span id=golf_copied_450 style='position:absolute;right:-14px;top:-30px; cursor: pointer;visibility:hidden;background:white;'>Copied!</span>
<textarea id='golft_450' style='position: absolute;left: -500%;'></textarea>
<img src='https://golf-lang.com/golf-copy-small-1.png' id='golfb' onclick='gg_copy(golft_450, code_450, golf_copied_450)' style='position:absolute;right:0;top:0; cursor: pointer;opacity:0.5;'/>
</div><br/>
Similar to the above example of listing files, but output results to a file (which is then read and the result displayed), and provide options "-a -l -s" to "ls" program:<br/>
<div class='code' style='position:relative;padding-right:16px;'>
<pre id='code_451'>
<span class="Statement"> exec-program</span> <span class="Constant">"ls"</span><span class="Identifier"> args</span> <span class="Constant">"-a"</span>, <span class="Constant">"-l"</span>, <span class="Constant">"-s"</span><span class="Identifier"> output-file</span> <span class="Constant">"lsout"</span>
<span class="Statement"> read-file</span> <span class="Constant">"lsout"</span><span class="Type"> to</span> final_res
<span class="Statement"> p-out</span> final_res</pre>
<span id=golf_copied_451 style='position:absolute;right:-14px;top:-30px; cursor: pointer;visibility:hidden;background:white;'>Copied!</span>
<textarea id='golft_451' style='position: absolute;left: -500%;'></textarea>
<img src='https://golf-lang.com/golf-copy-small-1.png' id='golfb' onclick='gg_copy(golft_451, code_451, golf_copied_451)' style='position:absolute;right:0;top:0; cursor: pointer;opacity:0.5;'/>
</div><br/>
Count the lines of file "config" (which is redirected to the standard output of "wc" program) and store the result in variable "ovar" (by means of redirecting the output of "wc" program to it), and then display: <br/>
<div class='code' style='position:relative;padding-right:16px;'>
<pre id='code_452'>
<span class="Statement"> exec-program</span> <span class="Constant">"wc"</span><span class="Identifier"> args</span> <span class="Constant">"-l"</span><span class="Identifier"> input-file</span> <span class="Constant">"config"</span><span class="Type"> output</span> ovar
<span class="Statement"> p-out</span> ovar</pre>
<span id=golf_copied_452 style='position:absolute;right:-14px;top:-30px; cursor: pointer;visibility:hidden;background:white;'>Copied!</span>
<textarea id='golft_452' style='position: absolute;left: -500%;'></textarea>
<img src='https://golf-lang.com/golf-copy-small-1.png' id='golfb' onclick='gg_copy(golft_452, code_452, golf_copied_452)' style='position:absolute;right:0;top:0; cursor: pointer;opacity:0.5;'/>
</div><br/>
<div class="vsub"><a id="See also"></a>See also</div>
<a name='Program execution'></a><span style="font-weight:bold;">Program execution</span><br/>
<a href='https://golf-lang.com/exec-program.html'>exec-program</a> <br/>
<a href='https://golf-lang.com/handler-status.html'>handler-status</a> <br/>
<span style="font-weight:bold;">See all</span> <br/>
<a href='https://golf-lang.com/documentation.html'>documentation</a><br/>
<!--ENDVDOC90-->
<br/><div style='width:100%;clear:both;'>
<hr/>
<!--GOLFFOOT77--><span style='font-size:80%'><a href="https://golf-lang.com/copyright.html">Copyright</a> (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.</span>
</div><br/></body></html>