为什么 sqlcmd -v foo="c:\path"吃“c:”?

发布于 2024-08-18 09:13:05 字数 270 浏览 3 评论 0 原文

我有 foo.sql 作为:

print 'foo=$(foo)'

然后我在 foo.cmd 中有以下 shell 脚本:

sqlcmd -i foo.sql -v foo="c:\path"

运行 foo.cmd 打印:

foo=\path

如何转义“c:”?是dos-shell 吃掉了它,还是sqlcmd 吃掉了它?

I have foo.sql as:

print 'foo=$(foo)'

Then I have in foo.cmd the following shell script:

sqlcmd -i foo.sql -v foo="c:\path"

Running foo.cmd prints:

foo=\path

how do I escape the "c:"? Is dos-shell eating it, or is it sqlcmd?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

留蓝 2024-08-25 09:13:05

cmd 的参数分隔符包括等号。我在其他情况下(例如 bjam.exe)看到必须引用整个参数序列才能正常工作。

试试这个:

sqlcmd -i foo.sql -v "foo=c:\path"

如果它仍然删除“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:

sqlcmd -i foo.sql -v "foo=c:\path"

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.

老旧海报 2024-08-25 09:13:05

好吧,我的错。以上确实有效。

我做错的是: 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:

燃情 2024-08-25 09:13:05

使用另一个 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'"

醉殇 2024-08-25 09:13:05

逃避反斜杠,

sqlcmd -i foo.sql -v foo="c:\\path"

实际上是你的 shell 吃掉了 \

Escape the backslash,

sqlcmd -i foo.sql -v foo="c:\\path"

It's actually your shell eating the \

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文