Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

q - loading script with try catch

Tags:

q-lang

kdb+

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

like image 517
tenticon Avatar asked Jan 18 '26 12:01

tenticon


2 Answers

You need to either escape the backslashes or use Unix-style paths, e.g.

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

So with exception-handling:

@[system; "l C:/some/path/startup.q"; `errormsg]
like image 159
James Little Avatar answered Jan 20 '26 03:01

James Little


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"
like image 37
Scott Avatar answered Jan 20 '26 03:01

Scott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!