Run cache program from command line.

Primary tabs

Greetings,

Is it possible to save Cache code into a file and then run it via command line?  

IE:  csession [ini] -U [ini] /path/cacheCodeFile.?

What I need to do is run a Cache script from the Linux command line.  The script will navigate data to produce a file and then it will exit back to the command line.

Thanks in advance for everyone's time.

  • 0
  • 0
  • 1867
  • 1
  • 1

Answers

Look at the documentation

csession instname "[label[+offset]]^routine"

Specifies the name of a COS program to run in user mode.

In addition to the specified formats, you can pass parameter lists consisting of string and/or numeric literals, as well as omitted (void) parameters, as follows:

where, for example, parameter-list is specified in the form "string literal",,-+-000123.45600E+07, and omitted parameters are passed to the target as $Data(parameter)=0.

Whitespace and shell meta characters must be quoted in an operating-system dependent form.

So, you can just call your code in routine or class with csession.

If you need another way, you can create any text file, with a list of commands, like if you would use them in csession manually. Where the last command should be HALT. While it is a code for csession, you can't use any multi line blocks and spaces at the beginning of the line.  And run it:

csession CACHE -UUSER < somecode.txt

If you need authorization in csession before executing code, just put login and password as a plain text in first two rows.

Comments

While it is possible, I would ensure that it is not possible to perform the actions within Caché first. This would enhance the application's ability to work better across platforms as well. Many of the functions that users would want to use have been compiled into classes, which you can refer to the class documentation here.

Its important to note that Caché reserves system memory for itself, so external calls would rely on the system's memory less that which has been reserved for the database. In most cases, a database is set up to run on its own system (i.e. the server is optimized to run the database only). I have been in a situation where someone did not recognize this and caused the server to lock up due to consuming the remaining memory.

As far as how to do this, it would depend on your Caché version and your Operating System, but it would be done with the $ZF function, which you can read up on here.