Synchronet v3.19b-Win32 (install) has been released (Jan-2022).

You can donate to the Synchronet project using PayPal.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
util:jsexec [2010/03/18 01:18] digitalmanutil:jsexec [2018/01/10 02:31] – Add additional Properties (stdio) and Functions digital man
Line 1: Line 1:
 ====== JSexec ====== ====== JSexec ======
  
-JSexec may be used to execute some Synchronet JavaScript files (e.g. ''*.js'', ''*.ssjs'') externally from Synchronet+JSexec may be used to execute some Synchronet JavaScript files (e.g. ''*.js'', ''*.ssjs'') externally from Synchronet.
  
-:!NoteSynchronet installation is required, though JSexec will execute scripts successfully even when Synchronet is not running.+===== Uses ===== 
 +  * Persistent execution of static services (e.g. [[:service:ircd]]) independent of Synchronet  
 +  * Background execution of timed events (e.g. [[:module:newslink]]) 
 +  * Command-line execution of sysop functions (e.g. [[:module:makeguest]]) 
 +  * [[:howto:apache|CGI]] generated dynamic HTML 
 + 
 +===== Independence ===== 
 + 
 +Synchronet installation is required for JSexec to function, though JSexec will execute scripts successfully even when Synchronet is not running.
  
 ===== Command Line ===== ===== Command Line =====
Line 36: Line 44:
         -!             wait for keypress (pause) on error         -!             wait for keypress (pause) on error
 </file> </file>
 +
 +==== Module ====
 +The ''module'' argument is optional if the standard input stream (''stdin'') is not a console (''tty''), allowing for [[#shebang]] support on Unix-like operating systems.
  
 ===== Additional Properties ===== ===== Additional Properties =====
Line 41: Line 52:
 Additional properties available to JavaScript scripts running from JSexec: Additional properties available to JavaScript scripts running from JSexec:
  
-^Property  ^Type     ^Description^+^Property   ^ Type     ^Description^
 |''jsexec_revision'' |string|[[dev:CVS]] revision of JSexec (example: ''%%"1.135"%%'')| |''jsexec_revision'' |string|[[dev:CVS]] revision of JSexec (example: ''%%"1.135"%%'')|
 |''jsexec_revision_detail'' |string |Verbose details about the JSexec build (example: ''%%"JSexec 1.136 Debug  Compiled Mar 15 2010 11:13:53 with GCC 3.4.2"%%'')| |''jsexec_revision_detail'' |string |Verbose details about the JSexec build (example: ''%%"JSexec 1.136 Debug  Compiled Mar 15 2010 11:13:53 with GCC 3.4.2"%%'')|
-|''env'' |string[] |Associative array of system environment variables (example: ''%%env["shell"]="/bin/bash"%%'')|+|''env''    Object |Associative array of system environment variables (example: ''%%env["shell"]="/bin/bash"%%'')
 +|''stdin''  | File   |Standard input stream | 
 +|''stdout'' | File   |Standard output stream | 
 +|''stderr'' | File   |Standard error output stream |
  
 +===== Additional Functions =====
 +
 +The following global methods (functions) are also available to JavaScript scripts running from JSexec:
 +
 +^Function     ^ Return Value ^ Description ^
 +|''log''      | String       | Log a message   |
 +|''read''     | String       | Read from stdin |
 +|''readln''   | String       | Read line from stdin |
 +|''write''    | String       | Write a string to stdout |
 +|''print''    | String       | Write a line to stdout (a.k.a. ''writeln'') |
 +|''printf''   | String       | Write a formatted string to stdout |
 +|''alert''    | String       | Print an alert message on the console |
 +|''prompt''   | String       | Prompt for user input |
 +|''confirm''  | String       | Get a yes/no confirmation |
 +|''deny''     | String       | Get a no/yes confirmation |
 +|''chdir''    | String       | Change the current working directory |
 +|''putenv''   | String       | Add or change an environment variable |
 ===== conio ===== ===== conio =====
 JSexec includes an instance of a special Console Input/Output class called ''conio''. JSexec includes an instance of a special Console Input/Output class called ''conio''.
Line 55: Line 86:
  
 FIXME FIXME
 +
 +===== shebang =====
 +
 +JSexec for non-Windows platforms will ignore the first line of the interpreted script if it begins with ''#!'', allowing for a [[wp>shebang (Unix)]] style script file where the first line of the script is something like:
 +<file>
 +#!/sbbs/exec/jsexec -c/sbbs/ctrl
 +</file>
 +
 +This allows JSexec scripts to be executed easily via [[:howto:apache|CGI]] as well as other command-line conveniences on Unix-like operating systems.
  
 ===== See Also ===== ===== See Also =====
-  * [[:custom:js|JavaScript]]+  * [[custom:javascript|JavaScript]]
   * [[:howto:apache|How To Use Apache HTTP Server with Synchronet]]   * [[:howto:apache|How To Use Apache HTTP Server with Synchronet]]
   * [[:util:|Utilities]]   * [[:util:|Utilities]]
  
 {{tag>javascript jsexec customization}} {{tag>javascript jsexec customization}}