q - loading script with try catch

410 views Asked by At

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

2

There are 2 answers

0
Scott On BEST ANSWER

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"
0
James Little On

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]