GOLF(2gg)

๐Ÿ“ฆ version 601.4.41, in ubuntu questing

๐Ÿ‘‘ GOLF(2gg) โ€” the exec-program glow-up

okay bestie, welcome to the GOLF(2gg) page from the Development section, and no cap this one is a banger ๐Ÿ’…


โœจ NAME โœจ

exec-program โ€” (program-execution) ๐Ÿซถ


๐ŸŽฏ PURPOSE ๐ŸŽฏ

Run a program. That's it, that's the whole vibe. execute it. ๐Ÿ’–


๐Ÿ“œ SYNTAX ๐Ÿ“œ

exec-program <program path> \
    [ args <program arg> [ , ... ] ] \
    [ status <exit status> ] \
    [ ( input <input string> [ input-length <string length> ] ) \
        | ( input-file <input file> ) ] \
    [ ( output <output string>  ) \
        | ( output-file <output file> ) ] \
    [ ( error <error string> ) | ( error-file <error file> ) ]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

exec-program runs whatever program you point it at with <program path>, and bestie, that path can be three whole things:

  • a program name with no path, as long as it lives somewhere in the path given by the PATH environment variable ๐ŸŒˆ
  • an absolute path ๐Ÿ’ซ
  • a path relative to the application home directory (peep directories for that, iykyk)

A program can take input arguments โ€” you hand those over as strings in the args clause. Got more than one? Separate them with a comma, periodt. There's no limit on how many input arguments you can pass, other than whatever the underlying Operating System says, and the OS is the one setting the rules there ๐Ÿ˜ญ

You can also name a status variable, <exit status>, and it'll hold the program's exit status. Quick heads up though: if the program got terminated by a signal, <exit status> is 128+signal_number. So say the program got killed with signal 9 (the KILL signal, iconic but rude ๐Ÿ’€), then <exit status> is 137 (that's 128+9). And any other kind of abnormal program termination โ€” like, where the program just did not set the exit code โ€” returns 126 as <exit code>. Noted, bestie ๐Ÿ“

Specifying program input and output is optional, it's giving very chill. But if the program has output and you're not capturing it in any way at all, that output gets redirected to a temporary file, and that file gets deleted once exec-program is done. Cute, clean, no leftovers ๐ŸŽ€

You can pass an <input string> straight to the program's standard input (stdin) using the input clause. If you don't use input-length, the length of that input is just the string length of <input string> โ€” otherwise, <string length> bytes get passed to the program. Or, if you'd rather, you can name a file <input file> with the input-file clause, and it gets opened and directed into the program's standard input (stdin) ๐ŸŒธ

Want the program's output (that's "stdout") in a file? <output file> via the output-file clause, slay. Or you can capture the program's output in <output string> via the output clause instead ๐Ÿ’œ

For the program's error output (that's "stderr"), use the error-file clause to get it into <error file>. Or capture the program's error output in <error string> via the error clause. Pick your fighter โœจ

Now the important part, listen up:

If <input file> can't be opened, GG_ERR_READ is reported in <exit status>. And if either <output file> or <error file> can't be opened, the status is GG_ERR_WRITE. ๐Ÿ˜ค

Also, in general, a program counts as successfully executed if it returns GG_OKAY (that's zero, the zero of dreams). Most programs returning a non-zero value mean failure, and we respect that ๐Ÿซก


๐ŸŒŸ EXAMPLES ๐ŸŒŸ

just run it, no extras

To simply execute a program that's in the path, with no arguments, no input, no output:

exec-program "myprogram"

grep era ๐Ÿ”

Run the grep program using a string as its standard input, to remove a line that contains "bad line" in it, and output the result into the ovar variable:

exec-program "grep" args "-v", "bad line" "config" input "line 1\nline 2\nbad line\nline 3" output ovar
print-out ovar

list the files, get the list ๐Ÿ’…

Get the list of files in the application home directory into buffer ovar and then display it:

exec-program "ls" output ovar

ls but extra โœจ

Similar to the example above of listing files, but output results to a file (which is then read and the result displayed), and provide options "-a -l -s" to the ls program:

exec-program "ls" args "-a", "-l", "-s" output-file "lsout"
read-file "lsout" to final_res
print-out final_res

wc said count them lines ๐Ÿงฎ

Count the lines of file config (which is redirected to the standard output of the wc program) and store the result in the variable ovar (by redirecting the output of the wc program into it), and then display:

exec-program "wc" args "-l" input-file "config" output ovar
print-out ovar

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • Program execution
  • exec-program exit-status
  • See all documentation

and that's the whole page, bestie!! you ate that ๐Ÿ’–โœจ this lil masterpiece is rockin' version $VERSION and it's dated $DATE, brought to you by the GOLF(2gg) girlies ๐ŸŽ€ bye diva, go execute something iconic ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from