Go to main content

Sncode from the Command Line

How to write and execute Sncode scripts from the command line

Sncode from the Command Line

NAME

cli_scripts - How to write and execute Sncode scripts from the command line.

DESCRIPTION

It is recommended to execute Sncode scripts from the command line whenever you have to run:

  • Very long operations that would otherwise hit the timeout limit when executed in the browser
  • Scheduled and/or repetitive maintenance tasks (e.g., archiving or stats)
  • Resource intensive operations

EXAMPLES

Your first CLI script

Create a simple file called test.sn (you must add the double curly brakets like usual): 

a = "Hello World";
a;

As you can see, there is no difference between a CLI script and one that is executed in the browser. 

Execute an uncompiled script (.sn) in the CLI

The simplest way:

sncode test.sn

When you have to specify the full path to your script (recommended):

sncode /path/to/your/script/test.sn

When there is no alias for the "sncode" command:

/usr/local/bin/sncode test.sn

When your script requires a specific project configuration file (e.g., for database access):

sncode /full/path/to/your/test.sn -c /path/to/your/config/project_name.conf

Note: When using options like -c or -e, you must specify the full path to your script. 

Execute a compiled script (.snc) in the CLI

The simplest way:

sncode -e /path/to/your/script.snc

When your script requires a specific project configuration file (e.g., for database access):

sncode -e /path/to/your/script.snc -c /path/to/your/config/project_name.conf

Advanced options

You may execute this command to get all available options:

sncode -h

Useful advanced option sncode -u: passing parameters to the script.

sncode /full/path/to/your/test.sn -u table=sed_test -c /path/to/your/config/project_name.conf

You can also pass multiple parameters as follow:

sncode /full/path/to/your/test.sn -u table=sed_test\&field=test -c /path/to/your/config/project_name.conf

In the script test.sn:

cgidata = cgidata();
cgidata;// return {"table":"sed_test","field":"test"}

AUTHOR

Written by Jean-Georges Guenard, <jg@sednove.com>

Edit

© 2024 extenso Inc. All rights reserved.