Search code examples
kdbq-lang

q - loading script with try catch


I have a q script on C:\some\path\startup.q that loads several other q scripts into the current session like this

\l C:\some\other\path\script1.q
\l C:\some\other\path\script2.q
\l C:\some\other\path\script3.q

Now, it could happen that I want to check several paths for script1.q etc.. E.g. when I am in a deploy environment instead of my local environment those paths are different. So I would like to try-catch the load operator along the lines of

@[\l;C:\some\other\path\script1.q;`errormessage]

which is of course nonsense. But I found the system command in q which is described here. For example

\w / lists memory usage
system "w" / same command

However, that doesn't work with \l

system "l C:\some\path\startup.q"

Thanks for the help


Solution

  • Backslash is the escape character for strings in kdb so the backslashes in your filepath are stopping the system command from working. To fix this you will need to escape your backslashes.

    Using the below should work for you:

    system "l C:\\some\\path\\startup.q"