Powershell SQLCMD

发布于 2024-07-25 03:27:11 字数 203 浏览 6 评论 0原文

我们在使用 Powershell 和 SQLCMD 时遇到了问题,当 -v 参数变量中有空格时,powershell 将无法运行该命令。

例如,

sqlcmd ... -v VAR="Some space"

有人以前经历过这种情况或知道如何解决该问题吗?

谢谢,

B

We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command.

e.g.

sqlcmd ... -v VAR="Some space"

Has anyone experienced this before or know how to fix the problem?

Thanks,

B

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

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

发布评论

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

评论(2

夜清冷一曲。 2024-08-01 03:27:11

上面的语法适用于 PS 命令行,但在脚本中失败。

我们为如何完成这项工作奋斗了很长时间。 我们的一位非常聪明的 QA 人员最终想出了以下结论:

$variableWithSpaces="one two three"
$mySqlCmd = "sqlcmd -E -S $dbServer -i $script  -v var=```"$variableWithSpaces```" "
Invoke-Expression $mySqlCmd 

插头丑陋,但它有效。

The syntax above works for the PS commandline but fails within a script.

We struggled a long time with how to make this work. One of our very clever QA guys finally came up with the following:

$variableWithSpaces="one two three"
$mySqlCmd = "sqlcmd -E -S $dbServer -i $script  -v var=```"$variableWithSpaces```" "
Invoke-Expression $mySqlCmd 

Plug ugly but it works.

最偏执的依靠 2024-08-01 03:27:11

Powershell 实际上会将参数作为 "VAR=Some space" 传递给程序。 也许 sqlcmd 会偶然发现这一点。 通过使用

VAR=`"Some space`"

,它将作为 VAR="Some space" 传递。 也许这可以解决问题。

Powershell will actually pass the parameter to the program as "VAR=Some space". Maybe sqlcmd stumbles over this. By using

VAR=`"Some space`"

instead it will get passed as VAR="Some space". Maybe that resolves the problem.

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