Difference between revisions of "Manual:DIL Manual/shell()"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
= integer shell(str : string); =  
+
= shell() =
 +
'''Function''' (integer). Starts a program from the server's <code>allow</code> directory.
  
−
  str    : The system command to execute and its parameters.
+
  shell(cmd : string)
−
  result : Will return 0 if a thread is successfully created. You won't know if the system command succeeded.
 
  
−
'''Examples'''
+
Runs <code>./allow/</code> followed by <code>cmd</code> through the system shell, in a thread of
 +
its own, from the directory the server runs in (<code>vme/bin</code>, so
 +
<code>vme/bin/allow/</code>). The game doesn't wait for it. The first word of <code>cmd</code> is
 +
the program; the rest are its arguments. wiz.zon uses it to start the build and deploy scripts.
  
−
  rc := shell("gh --subject hello");
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| cmd || string || The program in <code>vme/bin/allow/</code> and its arguments, as for a shell: <code>"compile.sh"</code>, <code>"test.sh olle golle"</code>.
 +
|}
  
−
This command would execute the vme/bin/allow/gh binary with the parameters shown above.
+
== Returns ==
−
If rc is zero then the thread was created successfully. But you wont know if the binary
+
Integer: 0 when the thread was started, otherwise the error code of starting it. It says nothing
−
was executed (the server doesn't wait for it to finish).
+
about the program itself: whether it ran and how it ended is written to the log only
 +
("success system(...)" or "fail system(...)"). It fails when <code>cmd</code> is a failed
 +
value; a string variable that was never set is a type error, and the program stops.
  
−
Using shell() you cannot directly execute any commands outside the allow/ directory.
+
== Notes ==
 +
* Only zones with access level 0 (the fourth column of <code>vme/etc/zonelist</code>) may use
 +
  it. Elsewhere it writes "attempt run shell() w/o access" to the zone's log and the program
 +
  stops.
 +
* A program name with <code>/</code>, <code>;</code> or <code>..</code> is refused (in the log).
 +
  Only that first word is checked: the arguments reach the shell as they are, so never put
 +
  text a player typed in them.
 +
* Pass a constant string. A string built in the call (<code>"x.sh " + name</code>) is freed
 +
  while the new thread may still be reading it.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin start_build(pc : unitptr);
 +
var
 +
  i : integer;
 +
code
 +
{
 +
  if (pc.level < 254)
 +
      quit;
 +
  i := shell("compile.sh");
 +
  act("The build starts. (" + itoa(i) + ")", A_ALWAYS, pc, null, null, TO_CHAR);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
Lets a high god start the build script <code>vme/bin/allow/compile.sh</code>, as the compiler
 +
room in wiz.zon does.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/dispatch()|dispatch()]]
 +
* [[Manual:DIL Manual/flog()|flog()]]
 +
* [[Manual:DIL Manual/access|access]]

Latest revision as of 23:20, 14 November 2026

shell()

Function (integer). Starts a program from the server's allow directory.

shell(cmd : string)

Runs ./allow/ followed by cmd through the system shell, in a thread of its own, from the directory the server runs in (vme/bin, so vme/bin/allow/). The game doesn't wait for it. The first word of cmd is the program; the rest are its arguments. wiz.zon uses it to start the build and deploy scripts.

Parameters

Name Type Meaning
cmd string The program in vme/bin/allow/ and its arguments, as for a shell: "compile.sh", "test.sh olle golle".

Returns

Integer: 0 when the thread was started, otherwise the error code of starting it. It says nothing about the program itself: whether it ran and how it ended is written to the log only ("success system(...)" or "fail system(...)"). It fails when cmd is a failed value; a string variable that was never set is a type error, and the program stops.

Notes

  • Only zones with access level 0 (the fourth column of vme/etc/zonelist) may use
 it. Elsewhere it writes "attempt run shell() w/o access" to the zone's log and the program
 stops.
  • A program name with /, ; or .. is refused (in the log).
 Only that first word is checked: the arguments reach the shell as they are, so never put
 text a player typed in them.
  • Pass a constant string. A string built in the call ("x.sh " + name) is freed
 while the new thread may still be reading it.

Example

dilbegin start_build(pc : unitptr);
var
   i : integer;
code
{
   if (pc.level < 254)
      quit;
   i := shell("compile.sh");
   act("The build starts. (" + itoa(i) + ")", A_ALWAYS, pc, null, null, TO_CHAR);
   quit;
}
dilend

Lets a high god start the build script vme/bin/allow/compile.sh, as the compiler room in wiz.zon does.

See also