为什么 sqlcmd -v foo="c:\path"吃“c:”?
我有 foo.sql 作为:
print 'foo=$(foo)'
然后我在 foo.cmd 中有以下 shell 脚本:
sqlcmd -i foo.sql -v foo="c:\path"
运行 foo.cmd 打印:
foo=\path
如何转义“c:”?是dos-shell 吃掉了它,还是sqlcmd 吃掉了它?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
cmd 的参数分隔符包括等号。我在其他情况下(例如 bjam.exe)看到必须引用整个参数序列才能正常工作。
试试这个:
如果它仍然删除“c:”部分,我会专注于 sqlcmd。我个人没有安装它来测试。这仅基于类似情况的经验。
cmd's argument delimiters include the equal sign. I've seen in other cases (such as bjam.exe) that the entire parameter sequence has to be quoted to work properly.
Try this:
If it still strips the "c:" portion, I'd focus on sqlcmd. I don't personally have it installed to test with. This is based solely on experience with similar situations.
好吧,我的错。以上确实有效。
我做错的是: sqlcmd -i foo.sql -v foo='c:\path'
(单引号,因为我试图将它们作为 ' ' sql 字符串传递),这是行不通的。它将砍掉 c:
OK, my mistake. the above does work.
What i did wrong was doing: sqlcmd -i foo.sql -v foo='c:\path'
(single quote, since I tried to pass them as ' ' sql string) that won't work. it will chop the c:
使用另一个 shell 会导致这种情况。
我刚刚通过 powershell 运行 sqlcmd 时遇到了这个。切换到使用 cmd.exe,它可以很好地使用
双引号来转义“:”和单引号,以便 sql 将变量值视为字符串。例如
sqlcmd -S 。 -d myDb -i .\test.sql -v pathToFile = "'D:\Temp\temp\My.csv'"
Using another shell causes this.
I just had this when running sqlcmd via powershell. Switched to using cmd.exe and it worked fine
double quotes to escape the ":" and single quotes so that sql treated the variable value as a string. e.g.
sqlcmd -S . -d myDb -i .\test.sql -v pathToFile = "'D:\Temp\temp\My.csv'"
逃避反斜杠,
实际上是你的 shell 吃掉了 \
Escape the backslash,
It's actually your shell eating the \