System-inquiry.xhtml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  3. <head>
  4. <title>System inquiry</title>
  5. <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
  6. <link rel="stylesheet" type="text/css" href="kawa.css"/>
  7. <script src="kawa-ebook.js" type="text/javascript"/>
  8. <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
  9. <link rel="prev" href="Overall-Index.xhtml" title="Index"/>
  10. <link rel="next" href="Processes.xhtml" title="Processes"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="System inquiry" epub:type="subchapter" id="System-inquiry">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">System inquiry</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p class="synopsis" kind="Variable"><span class="kind">Variable</span><span class="ignore">: </span><a id="idm139667869585696" class="indexterm"/> <code class="varname">home-directory</code></p>
  23. <div class="blockquote">
  24. <blockquote class="blockquote">
  25. <p>A string containing the home directory of the user.
  26. </p>
  27. </blockquote>
  28. </div>
  29. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667869582704" class="indexterm"/> <code class="function">command-line</code></p>
  30. <div class="blockquote">
  31. <blockquote class="blockquote">
  32. <p>Returns a nonempty list of immutable strings. The first element is
  33. an implementation-specific name for the running top-level
  34. program.
  35. The remaining elements are the command-line arguments,
  36. as passed to the <code class="literal">main</code> method (except for those
  37. flags processed by Kawa itself).
  38. </p>
  39. <p>The first element will depend on how the Kawa module was invoked.
  40. Kawa uses the following rules to determine the command name:
  41. </p>
  42. <div class="orderedlist" epub:type="list">
  43. <ol class="orderedlist" type="1">
  44. <li class="listitem" epub:type="list-item">
  45. <p>If the property <code class="literal">kawa.command.name</code> is set, that is used.
  46. This variable can be set on the <code class="literal">kawa</code> command line,
  47. for example from a script:
  48. </p>
  49. <pre class="screen">kawa -Dkawa.command.name="$0" foo "$@"
  50. </pre>
  51. <p>This variable is also set implicitly by the meta-arg option. FIXME.
  52. </p>
  53. </li>
  54. <li class="listitem" epub:type="list-item">
  55. <p>If we’re reading a source file that starts with the Unix command-file prefix
  56. ‘<code class="literal">#!/</code>’ then we use the name of the source file.
  57. The assumption is that such a file is an executable script.
  58. </p>
  59. </li>
  60. <li class="listitem" epub:type="list-item">
  61. <p>If the Java property <code class="literal">kawa.command.line</code> is set,
  62. then we use that (after stripping off text that duplicates
  63. the remaining arguments).
  64. The <code class="literal">kawa</code> program sets this property to the
  65. command line used to invoke it
  66. (specifically the contents of the entire <code class="literal">argv</code> array),
  67. before invoking the <code class="literal">java</code> program.
  68. </p>
  69. </li>
  70. <li class="listitem" epub:type="list-item">
  71. <p>If the Java property <code class="literal">sun.java.command</code> is set,
  72. then we use that (after stripping off text that duplicates
  73. the remaining arguments), and then prepending the string <code class="literal">"java "</code>.
  74. The OpenJDK <code class="literal">java</code> program sets this property.
  75. </p>
  76. </li>
  77. <li class="listitem" epub:type="list-item">
  78. <p>If all else fails, the command name is <code class="literal">"kawa"</code>.
  79. </p>
  80. </li>
  81. </ol>
  82. </div>
  83. </blockquote>
  84. </div>
  85. <p class="synopsis" kind="Variable"><span class="kind">Variable</span><span class="ignore">: </span><a id="idm139667869569648" class="indexterm"/> <code class="varname">command-line-arguments</code></p>
  86. <div class="blockquote">
  87. <blockquote class="blockquote">
  88. <p>Any command-line arguments (following flags processed by Kawa itself)
  89. are assigned to the global variable ‘<code class="literal">command-line-arguments</code>’,
  90. which is a vector of strings.
  91. </p>
  92. </blockquote>
  93. </div>
  94. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667869565984" class="indexterm"/> <code class="function">process-command-line-assignments</code></p>
  95. <div class="blockquote">
  96. <blockquote class="blockquote">
  97. <p>Process any initial command-line options that set variables.
  98. These have the form <code class="literal"><em class="replaceable"><code>name</code></em>=<em class="replaceable"><code>value</code></em></code>.
  99. Any such command-line options (at the start of the command-line)
  100. are processed and removed from the command-line.
  101. </p>
  102. <pre class="screen">$ java kawa.repl -- abc=123 def
  103. #|kawa:1|# (write (command-line))
  104. ("java kawa.repl --" "abc=123" "def")
  105. #|kawa:2|# (process-command-line-assignments)
  106. #|kawa:3|# (write (command-line))
  107. ("java kawa.repl -- abc=123" "def")
  108. #|kawa:4|# abc
  109. 123
  110. </pre>
  111. <p>This function is mostly useful for Kawa applications
  112. compiled with the <code class="literal">--main</code> option.
  113. (It is used to set XQuery <code class="literal">external</code> variables.)
  114. </p>
  115. </blockquote>
  116. </div>
  117. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667869559872" class="indexterm"/> <code class="function">get-environment-variable</code> <em class="replaceable"><code>name</code></em></p>
  118. <div class="blockquote">
  119. <blockquote class="blockquote">
  120. <p>Many operating systems provide each running process with
  121. an environment conisting of environment variables.
  122. (This environment is not to be confused with the
  123. Scheme environments that can be passed to <code class="literal">eval</code>.)
  124. Both the name and value of an environment variable are
  125. strings. The procedure <code class="literal">get-environment-variable</code>
  126. returns the value of the environment variable <em class="replaceable"><code>name</code></em>,
  127. or <code class="literal">#f</code> if the environment variable is not found.
  128. (This uses the <code class="literal">java.lang.System:getenv</code> method.)
  129. It is an error to mutate the resulting string.
  130. </p>
  131. <pre class="screen">(get-environment-variable "PATH")
  132. ⇒ "/usr/local/bin:/usr/bin:/bin"
  133. </pre>
  134. </blockquote>
  135. </div>
  136. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667869552688" class="indexterm"/> <code class="function">get-environment-variables</code></p>
  137. <div class="blockquote">
  138. <blockquote class="blockquote">
  139. <p>Returns the names and values of all the environment variables as an alist,
  140. where the car of each entry is the name of an environment variable,
  141. and the cdr is its value, both as strings.
  142. It is an error to mutate any of the strings or the alist itself.
  143. </p>
  144. <pre class="screen">(get-environment-variables)
  145. ⇒ (("USER" . "root") ("HOME" . "/"))
  146. </pre>
  147. </blockquote>
  148. </div>
  149. </section>
  150. <footer>
  151. <div class="navfooter">
  152. <p>
  153. Up: <a accesskey="u" href="Miscellaneous.xhtml">Miscellaneous topics</a></p>
  154. <p>
  155. Previous: <a accesskey="p" href="Android-view-construction.xhtml">Android view construction</a></p>
  156. <p>
  157. Next: <a accesskey="n" href="Processes.xhtml">Processes</a></p>
  158. </div>
  159. </footer>
  160. </body>
  161. </html>