commandbox on windows question: in my box.json i ...
# box-products
w
commandbox on windows question: in my box.json i have a directive to copy some ssl cert files to a local folder. using a unc path fails to copy the files, but using a mapped drive to do the same thing works fine. doesn't work:
Copy code
"scripts":{ 
    "preServerStart":"cp \"\\\\servername\\folder\\subfolder\\\" \".\\certs\\\""
}
works:
Copy code
"scripts":{ 
    "preServerStart":"cp \"T:\\folder\\subfolder\\\" \".\\certs\\\""
}
where T: is simply mapped to \\servername\ is there some special syntax i'm missing for using unc paths here?
t
have you tried posix separators rather than escaping?
w
meaning / vs \\ ?
i have not, but can try
silently fails as well
d
Does the mapped drive have different permissions for the cf user than the raw unc path maybe?
w
i don't believe so, but will check
r
Probably a permissions issue. Your mapping is probably using your credentials or whatever you used to map the drive and UNC is probably using guest or other credentials.
w
suffice to say then that you've successfully referenced UNC paths from within commandbox's scripting area or elsewhere?
d
Do end users access this, or can its access be allowed only for the cf server user?
w
well, the user in this case i assume is commandbox, it's a pre start up command
i'll try starting it as administrator and see if that changes anything
running as admin didn't change anything, silently fails
will do some more testing
d
can you try running that in the repl?
w
sure
d
you'd at least see the error then, hopefully
w
no error, but no files copied
d
from the repl?
how about checking fileExists() and/or directoryExists() from there
w
yes, and running it using the mapped drive letter instead from the repl works without issue
t
what about directoryList
w
how to run that directly in the repl?
assuming it can
b
@websolete I assume you're missing some escaping there
The UNC network path is already
Copy code
\\servername
and when run from the CLI, since
\
is an escape char, the command needs to become
Copy code
cp \\\\servername ...
and when stored in JSON, where
\
is also an escape char, the JSON string needs to become
Copy code
"cp \\\\\\\\servername ..."
d
fun!
w
this is literally what i am trying, with foldernames replaced:
Copy code
"preServerStart":"cp \"\\\\server\\folder1\\folder2\\folder3\\\" \".\\certs\\\""
b
If you look at the debuggin output on a
--verbose
server start, it should output the
preServerStart
command and you should see it with too few slashes
w
i do, and it was escaped correctly, just doesn't do anything. no complaints, but no copy either
b
Mixing double and single quotes and help simplify a quoted string inside of JSON
JSON requries
"
but CLi commands can use
'
to demarcate a string
w
will try ' in the command then
b
To be clear, your last example above is not the same as what I suggested
I only see one set of escapes in your example
which would be fine if you were just running it from the CLI directly and not storing it in JSON
w
when i run verbose, i see the cp command with the path correctly normalized with the slashes
b
show me
I don't know if your version of "correctly" is the same as mine 🙂
There should still be four slashes in the command (
\\\\
)
Again, I just tested this locally and just to run the command I need to already escape each slash once
Copy code
ls \\\\192.168.1.197\C$
w
will msg you a screenshot directly since it has live paths, sec
b
So you need to double that to store it in JSON
If you only see
cp \\foo
in your logs, then that means you're only REALLY running
cp \foo
And since
cp
uses file globs, it won't complain if the file glob matches nothing
And, looking at the screenshot you just sent me, that's exactly what's happening 🙂
w
pasted you an image of the box.json and the commandbox output
b
So do you know what to do to fix it now?
w
double up on all the slashes i already have?
you need TWO LEVELS of escaping
Once for the JSON, and again for the CLI command parser
w
just unclear to me why using the mapped drive letter with the same single escaping it worked fine
will try and double them up again
b
A drive letter is not the same as a UNC path 🙂
CommandBox parser will only care about a
\
IF AND ONLY IF it's preceding a character that needs escaping
So you can have
\A
\B
\C
all day long and it won't care
but
\
itself requires escaping, so
\\
matters now
w
i was referring to the rest of the esacped \ in the path, but just a moment, doubling up on the unc prefix slashes
b
I do this on purpose, otherwise, life would suck on windows because ALL your paths would have to be
C:\\windows\\foo\\bar
etc
Basically, a single backslash will just remain as it is. but if you want to have two in a row, now you need to deal with the fact taht the first backslash will be cancelling out the second so you need to escape.
This is also why i got rid of the
\t
and
\n
escpares for tabs and new lines in older versions of CommandBox because they caused too much trouble
And path like
C:\foo\temp
turned into
C:\foo    emp
!
Note, JSON is not as kind as I am. It will require every single
\
to be escaped regardless of what char it preceeds
w
well, apparently i am an idiot, since it still doesn't work. if you insist that it should work, and that the pathing should be \\\\\\\\servername in the box.json file, then i'll have to assume it's a permission issue, since it doesn't work, but doesn't raise any exceptions either
b
There maybe more than one thing going on here. Can you try adding a glob pattern so you're copying
subfolder\*
The
cp
command doesn't output every file (since there could be thousands) but as long as it copies at least one file, you'll see
Copy code
File copied to ....
Also, a quick note, when testing something like this, the
--dryRun
flag comes in super handy so it doesn't take as long to test
That will go through all the plumbing to start your server, but not actually start it.
w
ok, well, called into a meeting so i'll have to battle this again a bit later. thanks for the help meanwhile
b
You can also do some debugging by just adding something like
Copy code
ls path
to the package script to see what files its finding. Also, quoting arguments in CommandBox is only necessary if there is a space or a special char like
=
inside the string. Looking at the real paths in your screenshot you DM'd me, you should be fine leaving off the quotes for readability.
w
just to close the loop on this, i screwed up the unc path that was mapped to a drive letter, was incorrect. correcting the unc path reference and using the last round of suggested escaping of \ resolved my issue, thanks.
👍 1