When we open the ``command interface'' we arrive at a screen with the prompt (it can be different)
C:>It does not necessarily mean that we are in the root directory of C. To know the directory at which we are, we have to type
C:\>chdir C:\This does indicate that we are located in the directory 'c:
But now we are interested in running files from outside the directory. This is important because we can have data in different directories and we do not want to copy the programs in each of them.
As an example we are going to create a `bat' file in another directory that would act as an external program. First of all, we created a directory called `j' in `D:' (we place the directory in another device but any other place would function properly). Then, we create inside the directory a file called 'example.bat' (placed in the directory D:
j ) that prints a sentence. To create the file we can use some program like `edit' (that is present in the operating system), but if we use more advanced programs, we must take care that the program does not introduce additional extensions such as `example.bat.txt' and that the program stores data in plain text (you can check it with the command `type example.bat' ). The file `example.bat' could contain the next text:
echo "this is an example"Our objective is to run this `bat' file from outside of the directory where it has been placed. Of course, we could execute the file with the command:
c:\>D:\j\example c:\>echo "this is an example" "this is an example" c:\>But we are not interested in this method because such long names are difficult to type (there can be a lot of levels) and, even more importantly, because we could decide to change the place of the directory where `example.bat' resides and everything would become out of order. To achieve our objective we need that the operating system searches for the file. We indicate to the system where the executable files are going to be found with the command `path'. It is very important that we add the new location without destroying the preexisting paths. To do that, we type
Path D:\j;%path%Now, we can execute the program from anywhere.
c:\>example c:\>echo "this is an example" "this is an example" c:\>Notice that we had not indicated where the program is located. We got an additional advantage: we have a command that can be called from inside Scilab.
If we are using ``example'' frequently, it can be convenient to make the path persistent. It can be done by including the same line in the file ``autoexec.bat'': we open the file (it is located in C:
) with an editor, we include the same line (``path D:
j;%path%'') and save the new file with the same name. So, when we open a command window the programs contained in ``D:
j'' can be called from any other directory.
From now, we are going to center in Linux systems but most topics are easily generalized to Windows systems. (One of the advantages of Scilab is that it can be used in Windows or UNIX systems without additional costs or translation of code). Some commands can be different in Linux and Windows (command 'type' in Windows is equivalent to `cat' in UNIX, `dir' is equivalent to 'ls', and `chdir' without arguments is equivalent to 'pwd'). If you are running Windows, you can easily translate the expressions.
If you arrived here, let me give you an advice: install Linux. Today is a good day to do it. If you get over the initial difficulties, in only two months you will be learning much more than you can imagine and you will always remember this small tutorial.