仅在从jenkins运行时获取“OSError:exception:访问冲突写入0x00000000”

2024-10-04 05:33:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有visual studio 2017 控制台应用程序启动python脚本(python解释器版本3.7),python脚本使用C dll

当我在degug模式下运行这个Console应用程序时,一切都很好,当我通过cmd执行它时,一切都很好。 当我在Jenkins上实现它时,问题来了-使用“Excecute windows batch command”我使用与CMD相同的命令,这很有效, 它开始运行得很好,但作为python脚本中从C dll访问方法(QLIB_IsPhoneConnected方法),它给了我错误“OSError:exception:访问冲突写入0x00000000”。 此外,我尝试从“CMD as administrator”运行脚本,但在同一步骤中失败。我检查了Jenkins的“Excecute windows批处理命令”,发现它“不是”以管理员身份运行。 总结:从Jenkins的“Excecute windows批处理命令”(我发现它不是Administra或previlages)或从“CMD as administrator”运行visual studio可执行文件时出现错误,但在调试模式下运行visual studio或从CMD(非administrator)运行visual studio时没有出现错误

以下是相关的代码部分:

Visual studio(python runner):

ProcessStartInfo start = new ProcessStartInfo();
start.FileName = _pythonInterpeterDir + @"python.exe";
start.Arguments = string.Format("{0} {1}", _pythonInterpeterDir + @"QTM.py", command);
start.RedirectStandardOutput = true;
start.UseShellExecute = false;
using (Process process = Process.Start(start))
{
    using (StreamReader reader = process.StandardOutput)
    {
        results = reader.ReadToEnd();
    }
}

Python访问C dll:

from ctypes import *
import time
import QRCT

qmslDllName = 'C:\\Program Files (x86)\\Qualcomm\\QDART\\bin\\QMSL_MSVC10R.dll'
QLIB_IsPhoneConnected = qmslDll['QLIB_IsPhoneConnected']
QLIB_IsPhoneConnected.restype = c_uint8
QLIB_IsPhoneConnected.argtypes = [c_uint32]

def isPhoneConnected(self):
       status = QLIB_IsPhoneConnected(c_uint32(self.handle))

请帮助我了解从Jenkins“Excecute windows批处理命令”运行与CMD之间的区别


Tags: import命令脚本cmdwindows错误startdll