Skip to content

Commit

Permalink
Add EnvSet
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent e41f1b5 commit b4c13bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 11 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ <h2>Table of contents </h2>
<li class="x11">
<a href="#EnvGet.htm">EnvGet</a>
</li>
<li>
<a href="#EnvSet.htm">EnvSet</a>
</li>
<li>
<a href="#Menu.htm">Menu</a>
</li>
Expand Down Expand Up @@ -2386,6 +2389,10 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="x11 calibre4"><a href="#EnvGet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">EnvGet</a></td>
<td height="16" class="calibre4">Retrieves an environment variable.</td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#EnvSet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">EnvSet</a></td>
<td height="16" class="calibre4">Sets an environment variable for usage in Run/RunWait.</td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#Loop.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Loop (normal) </a></td>
<td height="16" class="calibre4">Perform a series of command repeatedly: either the specified number of times or until <a href="#Break.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">break</a> is encountered. </td>
Expand Down Expand Up @@ -2918,7 +2925,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
return</pre>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="EnvSet.htm" href="#EnvSet.htm">#</a> <h2 class="calibre17">EnvSet</h2>
<hr size="2" class="calibre24" />
Expand Down Expand Up @@ -2949,10 +2956,9 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<p class="calibre8"><a href="#ErrorLevel.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Remarks</strong></p>
<p class="calibre8"> This command exists separately from <a href="#SetEnv.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetEnv</a> because unlike AutoIt2, AutoHotkey does not store its variables in the environment. This is because performance would be worse and also because the OS limits environment variables to 32K (AutoHotkey variables, including the <a href="#Clipboard.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">clipboard</a>, are essentially unlimited in size).</p>
<p class="calibre8">Unless <a href="#EnvUpdate.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">EnvUpdate</a> is used, an <a href="#Variables.htm__env" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">environment variable</a> set in this way will only be accessible to programs that the script spawns via <a href="#Run.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Run</a> or <a href="#Run.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">RunWait</a>.  Once the script terminates, the variables will cease to exist.</p>
<p class="calibre8">Note: An EnvGet command is not provided because referencing a blank or undefined variable will automatically trigger that behavior. For example, in the following line, the value of the ProgramFiles variable (if undefined in the script) will be fetched from the environment: <br class="calibre12" /> TargetFile = %ProgramFiles%\Something\setup.ini </p>
<p class="calibre8 x11">Use this to export variables to be accessed by sub processes spawned by Run / RunWait.</p>
<p class="calibre8"> <span class="rm">This command exists separately from <a href="#SetEnv.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetEnv</a> because unlike AutoIt2, AutoHotkey does not store its variables in the environment. This is because performance would be worse and also because the OS limits environment variables to 32K</span> (AutoHotkey variables, including the <a href="#Clipboard.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">clipboard</a>, are essentially unlimited in size).</p>
<p class="calibre8"><span class="rm">Unless <a href="#EnvUpdate.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">EnvUpdate</a> is used,</span> an <a href="#Variables.htm__env" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">environment variable</a> set in this way will only be accessible to programs that the script spawns via <a href="#Run.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Run</a> or <a href="#Run.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">RunWait</a>.  Once the script terminates, the variables will cease to exist.</p>
<p class="calibre8"><span class="rm">Note: An EnvGet command is not provided because referencing a blank or undefined variable will automatically trigger that behavior. For example, in the following line, the value of the ProgramFiles variable (if undefined in the script) will be fetched from the environment: <br class="calibre12" /> TargetFile = %ProgramFiles%\Something\setup.ini</span> <span class="x11">Use EnvGet to retrieve env vars. AHK_X11 behaves like #NoEnv in newer AHK versions by default.</span> </p>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Related</strong></p>
<p class="calibre8"><a href="#EnvUpdate.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">EnvUpdate</a>, <a href="#SetEnv.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetEnv</a>, <a href="#Run.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Run</a>, <a href="#Run.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">RunWait</a> </p>
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/misc/env-set.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# EnvSet, EnvVar, Value
class Cmd::Misc::EnvSet < Cmd::Base
def self.min_args; 2 end
def self.max_args; 2 end
def run(thread, args)
env_var, val = args
ENV[env_var] = val
end
end

0 comments on commit b4c13bf

Please sign in to comment.