首页 > 解决方案 > 在 SQL Server 中执行 bash 脚本

问题描述

我已经为 bash 编写了一个脚本,并在 Windows 10 上安装了 bash,因此当尝试在命令提示符下运行该脚本时,请编写以下语法:

bash -c "/home/behzad/SIP-CMD-BYE_OLT-CMD-ACT.sh 09400098129 1234 8 2
 1 1 99 3 2001"

一切都好!现在我想在 SQL Server 中运行该脚本,为此在 SQL Server 中编写此 T-SQL:

EXEC master..xp_CMDShell 'bash -c "/home/behzad/SIP-CMD-BYE_OLT-CMD-ACT.sh 09400098129 1234 8 2 1 1 99 3 2001"'

但 SQL Server 只显示字符结果W,而 bash 脚本不起作用。我该如何解决这个问题?谢谢大家。

标签: sql-server

解决方案


试试这个:

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

推荐阅读