Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Scala, is it possible to write a script which refers to another script

I am currently looking at using Scala scripts to control the life-cycle of a MySQL database instead of using MS-DOS scripts (I am on Windows XP).

I want to have a configuration script which only holds configuration information, and 1 or more management scripts which use the configuration information to perform various operations such as start, stop, show status, etc .....

Is it possible to write a Scala script which includes/imports/references another Scala script?

I had a look at the -i option of the scala interpreter, but this launches an interactive session which is not what I want.

like image 876
Guillaume Belrose Avatar asked Sep 21 '10 13:09

Guillaume Belrose


3 Answers

According to Scala man, script pre-loading only works for interactive mode.

As a workaround, you can exit the interactive mode after running the script. Here's the code of child.bat (script that includes another generic one):

::#!
@echo off
call scala -i genetic.bat %0 
goto :eof
::!#
def childFunc="child"

println(geneticFunc)
println(childFunc)
exit;

genericFunc is defined at genetic.bat

The output of child.bat:

>child.bat
Loading genetic.bat...
...    
geneticFunc: java.lang.String
Loading child.bat...
...
childFunc: java.lang.String
generic
child
like image 91
Vasil Remeniuk Avatar answered Nov 13 '22 04:11

Vasil Remeniuk


I'd use Process and call the other Scala script just like any other command.

like image 27
Daniel C. Sobral Avatar answered Nov 13 '22 04:11

Daniel C. Sobral


One option would be to have a script which concatenates two files together and then launches it, something like:

@echo off
type config.scala > temp.scala
type code.scala >> temp.scala
scala temp.scala
del temp.scala

or similar. Then you keep the two seperate as you wished.

like image 1
Matthew Farwell Avatar answered Nov 13 '22 06:11

Matthew Farwell