Quadruple Backslashes

No, Quadruple Backslashes is not a college rock band (that I know of). But maybe it should be one. Anyway, ever see a quadruple backslashes on a path in a batch file? Like this:

SET FILE=\\\\some-server\\path-to-app-folder\\app\\data.txt

What’s going on here? This is a UNC path, and the normal form is like this:

SET FILE=\\some-server\path-to-app-folder\app\data.txt

Let’s say we are doing a data import in a MaxL script:

import database Sample.Basic data
    from data_file "$FILE"
    using server rules_file "LdAll"
    on error write to "errors.txt";

In many scripting languages, backslashes are special. They are used to “escape ” things inside of strings. What if you need a newline inside of a string? That’s \n. What if you want a tab? That’s \t. What if you want to print a backslash itself? You can’t just put a single backslash in because then the interpreter thinks that the next character is something special. So to write out just a backslash you escape a backslash itself (so it’s \\).

To further complicate things, many scripting languages have a notion of interpolated and non-interpolated strings. That means that strings contained inside of double quotes (“This is a double quoted string!”) have their contents parsed/scanned for special characters. Strings in single quotes don’t (‘This is a single quoted string!’). So in the single-quoted string, we can sometimes (not always) get away with doing whatever we want with backslashes. But if we use the single quoted string we can’t stick variables in it.

So now we need a double quoted string so we can put variables in it, but this makes putting in backslashes for our UNC path a little complicated. No worries – just escape the backslashes. Returning to our quadruple backslashed MaxL example that is surrounded with double quotes, what’s happening is that MaxL parses the string contents (the stuff between the double quotes) and the four backslashes become two backslashes in the final string. The double backslashes in the other parts of the UNC path get translated into a single backslash.

The final resulting string has the two backslashes to start the UNC path and any other path delimiters are just single backslashes.

Normal Paths

If you are just loading a file from a normal, non-networked path (or it’s a mapped drive), and you’re on Windows, then I highly recommend just using forward slashes to delimit the path. For example, consider an input file at D:\Hyperion\data.txt. Your double quoted string would be D:\\Hyperion\\data.txt, which gets translated down to just single quotes. For the last decade or more, Windows has had awesome support for the more traditional forward slash Unix path separator, meaning you can just use D:/Hyperion/data.txt. The forward slash isn’t special at all so you don’t need to escape it. You can’t use double forward slashes to denote a UNC path, though, so //server-name/path/to/file.txt will not work, thus requiring some backslash kung foo to get working.

10 thoughts on “Quadruple Backslashes

  1. Jason
    You don’t need to do call it as “$FILE”, you can pass %FILE% to MaxL and use $1

    • So that’s actually a post for another day. :) As far as personal MaxL style goes, I am not a fan at all of “positional parameters” (using $1, $2, etc.) I prefer to have variables. But yes, you are correct.

  2. Unix Environment: For some reason it is not recognize the file (LoadFile)….it says it does not exist!

    Please advise!

    import database Hot.IP dimensions from data_file “$ARBORPATH/LoadFile.csv” using server rules_file ‘Test’ on error write to ‘/essbase/script/logs/CC.txt’;

    • Usually for troubleshooting these I confirm the value of the variable, such as doing an echo statement with $ARBORPATH/LoadFile.csv so that it prints out the name it’s trying to load, and I can verify that the ARBORPATH is correct.

      Sometimes the environment variable is set for your user but not for the user running the Hyperion automation. Sometimes you need to export the variable (using your shell’s proper export command/syntax). Another thing to check is the permissions on the file. It’s possible that the user running the automation doesn’t have read privileges on that folder/file, also causing the error.

      Basically, just simplify the problem and work incrementally to find out where the problem is — good luck.

  3. 1) echo $ARBORPATH/LoadFile.csv prints out –> /LoadFile.csv
    2) Permissions on file LoadFile.csv –> rwxrwxr-x
    3) Env Var is set for your user but not 4 the user running the Hyperion Automation —> Executing through MaxL Editor

    How I answered the questions completely…..Please advise!

  4. Hi Delance,

    It appears that your $ARBORPATH variable is not set correctly. This should point to a folder on your system that contains the LoadFile.csv file. As you can see from your output, this variable is currently set to nothing so that the file name it creates is just /LoadFile.csv. Therefore it seems that your first place to look is to make sure the variable is set with a value.

  5. Q1) Can ARBORPATH be defined in the MaxL Script editor under MaxL–>Set Variables. The Path Name = Variable and ARBORPATH = Value or does it have to be defined in Unix
    Q2) Can the data file come from my C:Drive as ‘C:\LoadFile.csv’ instead of ARBORPATH

    • Yes, you can set it in the MaxL script or a batch file calling the MaxL script. The MaxL technical reference has documentation on MaxL variables.

      If you can run the MaxL script itself from your workstation then you could possibly modify it to load a local file. I don’t recommend changing the server script to force it to load a local file from your machine though. It’d better to just upload or otherwise copy the file from your machine to where the automation expects to find it, then run the script.

  6. Hi Jason,

    I am writing below script from Server B maxl Client,but getting error. Any clue will be of great help.

    Data load rules file is validating.

    Script:
    import database ‘App’.’DB’ data from server excel data_file “\\ServerA\local_path_to_file\excel.xls” using Server rules_file ‘dataload’ on error write to “local_path_to_file\errorfile.err”;

    Error:

    OK/INFO – 1019061 – Reading Rule SQL Information For Database
    OK/INFO – 1019025 – Reading Rules From Rule Object For Database
    ERROR – 1013295 – Server Request Fails with error code [1003086].
    ERROR – 1241101 – Unexpected Essbase error 1013295.

    Thanks
    Arun

    • Hi Arun, per the blog post I think you need more backslashes in the path that you have in double-quotes:

      “\\\\ServerA\\local_path_to_file\\excel.xls”

Leave a Reply

Your email address will not be published.