[英]How to pass variable to bcp command within powershell script
I am creating a string that I would like to pass to the bcp command from within a PowerShell script. 我正在创建一个字符串,该字符串想从PowerShell脚本中传递给bcp命令。 Here is the code that creates the string 这是创建字符串的代码
$fullFilePath = (pwd).path + "\$db.$table" + ".dat"
$copyExecString = "bcp $db.$table out $fullFilePath -E -N -Slocalhost"
I can paste the Write-host result of this into a command prompt and it runs just fine, but it won't work as follows: 我可以将此写入主机的结果粘贴到命令提示符中,并且运行正常,但不能按以下方式工作:
$fullFilePath = (pwd).path + "\$db.$table" + ".dat"
$copyExecString = "$db.$table out $fullFilePath -E -N -Slocalhost"
bcp $copyExecString
I also tried using the ampersand character before calling the bcp command, but to no avail 在调用bcp命令之前,我也尝试使用&字符,但无济于事
Any ideas on how to achieve this functionality would be greatly appreciated 任何有关如何实现此功能的想法将不胜感激
通过用空格将参数分开来标记它,而不是单个字符串:
& bcp $db.$table out $fullFilePath -E -N -Slocalhost
您可以使用Invoke-Expression
cmdlet确保在执行之前解析要执行的内容:
Invoke-Expression "bcp $copyExecString"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.