0

I’m writing a startup script for a kdb process (but I don’t think the type of process matters, could just as easily be python). I want the script to run my q file, and then inside the terminal, execute a line (myfunc[], for example). Trying the -c batch command gives “The system cannot find the file specified”. Any advice? Thanks. Code I am currently trying:

 cmd /k “q myqfile.q” -c “myfunc[]”
PythonParka
  • 134
  • 3
  • 13
  • Perhaps provide the full path? something like `cmd /k "c:\q\q c:\q\files\myqfile.q -c myfunc[]"` But your additional problem might be using multiple double quotes. Might I suggest a batch file called, let's say, `runq.cmd` with the command `"c:\path to q\q" "c:\path to q file\myqfile.q" -c "myfunc[]"`, then you would `cmd /c "c:\path to runq\runq.cmd"`. Though one has to wonder if you even need the `cmd /c` part anyway. – avery_larry Apr 23 '20 at 14:19
  • Please note that when you create your batch-file/command, not to use smart/curly quotes, **`“`**, and **`”`**, as you have in your question, but standard/straight ones, **`"`**. – Compo Apr 23 '20 at 14:34

3 Answers3

1
cmd /k "copy myqfile.q myqfile_.q & echo myfunc[] >> myqfile_.q & q myqfile_.q & del myqfile_.q"

I create a copy of myqfile.q, then append myfunc[] to the copy, then run the copy, and finally delete the copy.

Henrik4
  • 464
  • 3
  • 13
0

I think the fact it is q does matter here. I don't think you can pass a command to kdb/q like that. Add this to the bottom of myqfile.q:

myfunc[];
exit 0
Matt Moore
  • 2,705
  • 6
  • 13
  • This is what I was doing initially, but I’d like to be able to run it as stated in the question if possible. Could be the case that you can’t do it with q - I figured it was a generic way of passing commands to a terminal. I may have to go back to this method – PythonParka Apr 23 '20 at 14:39
0

You can do this from the command line but I don't know if it's best practice:

$ cat script.q
a:1;
func:{show a+x};
$ export QHOME=/opt/q && echo 'func[10]' | $QHOME/l64/q script.q
11
$
terrylynch
  • 11,844
  • 13
  • 21