DEV Community

Cover image for Scilab: Run Scilab in VS Code
Francisco Javier Moreno Vázquez
Francisco Javier Moreno Vázquez

Posted on • Updated on

Scilab: Run Scilab in VS Code

VS Code ❤ Scilab

Firstly, we need to have installed in our computer both Scilab and VS Code.

Download Code Extensions

We need only two extensions for run Scilab inside VS Code:

Scilab Extension

This extension is useful to make a highlight of the reserved word of Scilab syntaxis, this allow us to have our own customization in VS Code.

This is an example of the two sights of the Scilab in Code vs Scilab IDE:

Scilab Codes

Code Runner

This extension allow us run code snippets or code files for multiple languages and create custom commands.

Customize Code Runner for Scilab

In this step we need to customize the settings.json file, particulary, for the code-runner.executorMap. In this case, I created a Github Repo where I explain my VS Code configurations you can access to it and follow the instructions there, anyway, I'll explain how to configurate the file in this post:

  • Open settings.json.
  • Add code-runner.executorMap command.
  • Specify run mode instruction.
  • Add Scilab instruction to execute.

Open settings.json

This is the file where you can overwrite the default configurations of the editor.

You can access it with Ctrl + , and clicking like the image below:

settings.json

Add code-runner.executorMap command

If you are used to move and customize VS Code extensions, this step won't be a problem for you, either way I will show you how to do it.

In the settings.json file you can find a blank file (or not) and how its own name specify, the instructions needs to be in JSON format.



{
     "code-runner.executorMap": {},
}


Enter fullscreen mode Exit fullscreen mode

With this line we can begin to give instructions depending on any programming language we need to overwrite.

Specify run mode instruction

Foremostly, we need to understand what is a run mode in Scilab.

Scilab have 3 different ways to run its programs:

  1. Wscilex: runs the standar Scilab.
  2. Wscilex-cli: in this mode, Scilab is started as command line with advanced features still available (graphics, export, xcos, scinotes, help browser, ...).
  3. Scilex. this mode has two features:
    • This mode prevents loading the Java Virtual Machine. It starts faster and uses less memory.
    • Scilab is started as command line interpreter without any advanced features requiring the JVM: graphics, export, xcos, scinotes, help browser, other java interfaces, the Java module,... are not available.

We only need to be focus on Wscilex-cli and Scilex because we are goin to search for the instalation folder of Scilab (in my case, Scilab is installed in D:\Programs\scilab-6.1.0\ so replace for your path).

Add Scilab instruction to execute

If you want to run Scilab and visualize plots, graphs, images, etc, use the following script:



{
     "code-runner.executorMap": {
        // run Scilab with graphic Functions
        "scilab": "cd $dir && D:\\Programs\\scilab-6.1.0\\bin\\WScilex-cli.exe -nb -f $fileName",
    },
}


Enter fullscreen mode Exit fullscreen mode

But if you only want numerical results:



{
     "code-runner.executorMap": {
        // run Scilab from VSCode
        "scilab": "cd $dir && D:\\Programs\\scilab-6.1.0\\bin\\Scilex.exe -nb -quit -f $fileName",
    },
}


Enter fullscreen mode Exit fullscreen mode

In both cases we have flags that specify different things:

  • -nb: "no banner": Cancels the display of the Scilab's loading message.
  • -quit: This option forces scilab to always exit after the instruction(s) passed with the -e option, or the script referred to by the -f option, have been executed, even in case of a runtime error. This option should always be used in batch mode.
  • -f file: This option execute the file which is specified.

For $dir and $fileName, these are options nativately used in code-runner configuration.

And that is everything you need to begin with Scilab in VS Code!!

scilab hello

Top comments (6)

Collapse
 
kwasposer profile image
kwasposer • Edited

Ubuntu Linux version: -quit is important in case you want to rerun the *sce file

{
// run Scilab with graphic Functions
"code-runner.executorMap": {
"scilab": "cd $dir && /home/Tools/scilab-2024.0.0/bin/scilab-cli -nb -quit -f $fileName",
},
}

Collapse
 
danzisky profile image
Daniel C Nwaeke

Thank you very much, you really helped me out❤️

Collapse
 
andyvalds3 profile image
Andy Valdés

Muchas gracias. Una consulta, existe la posibilidad de utilizar input en Code?, ejm

pcp=input ("Introduzca la contrapresion: ")

slds.

Collapse
 
fcomovaz profile image
Francisco Javier Moreno Vázquez

lamento mucho la ausencia😅 pero sí, en este caso el compilador que debes de usar y configurar en el vscode es el de WScilex-cli.exe ya que tenemos que usar la consola normal de scilab.
¡¡¡Saludos!!!

Collapse
 
kousshikk profile image
Kousshikk

In output result isn't showing. saying [Done] exited with code=3221225781 in 0.078 seconds

Also nothing in terminal too

Collapse
 
vimsrocz profile image
Vimal

Hi

Customise code is done but its not working. Do you have time to resolve the issue with mac for XCOS? Are you developer?