python - 从 SQL Server 代理运行 Powershell 脚本(运行其他 exe 文件)
问题描述
我不确定为什么当我在 SQL Server 代理中运行时,这部分 Python 脚本不能完成这项工作。
这个 python 脚本来自“ConvertToBAK.py”。
for f in glob.glob(r'Z:\\TestPCC\\Yesterday\\*.SQB'):
os.system( f'SQBConverter "{f}" "{f[:-4]}.bak" {password}' )
所以,我运行 Powershell 来调用这个 Python 文件 (ConvertToBak.py)。
当我在 SQL Server 代理之外运行这个 Powershell 脚本时,一切正常。
我有以下 PowerShell 脚本。
$path = 'Z:\TestPCC'
$file = 'ConvertToBAK.py'
$cmd = $path+"\\"+$file # This line of code will create the concatenate the path and file
Start-Process $cmd # This line will execute the cmd
SQBCoverter 是第三方(RedGate)应用程序的 exe 文件,它基本上将 SQB 文件格式转换为 BAK 文件格式。
使用相同的 Python 代码,SQL Server 代理完成其他任务(例如将文件从这里移动到那里),但它只是跳过/不执行此任务。
有什么我需要添加到 Powershell 或者运行第三方/外部 exe 文件(SQBConverter)的 SQL Server 代理是否存在权限问题?
顺便说一句,我的 SQL Server 代理登录是我自己的帐户,因为使用其他系统帐户,我无法执行 Python 代码中的一些任务。
我还检查了这个特定 exe 文件的权限问题,并为所有用户授予了完全权限。
解决方案
从您所说的来看,应该没问题,但是如果要确保以适当的用户权限启动脚本,您还可以将相应的凭据直接传递给Start-Process Cmdlet:
#Use parameters to obtain username and password, avoid to hard-code them here.
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process $cmd -Credential ($credentials)
推荐阅读
- bluetooth-lowenergy - 限制 ble 外围应用程序仅连接一个中央
- c# - 使用 Repository 模式、工作单元和 autofac 依赖注入实现 webapi
- javascript - Firestore 云功能给出日志问题
- html - Google Maps API:使用总标记制作变量
- 2sxc - 添加刚刚安装的应用程序时出现错误
- python - 如何将 tf.contrib 转换为 Tensorflow 2.0
- python - 从 Sharepoint 下载 python
- selenium-webdriver - 在 Capybara 中查看 JavaScript 控制台输出
- python - 413“请求实体太大”使用 Python 和 postcodes.io API
- c# - 损坏的 aspx 和 cs 文件显示为 aspx.cs.lokf 我正在使用 vs2015