通过子进程测试C程序.PYTHON中的Popen会引发cygwin错误

我现在是一名学习C的学生,我一直在尝试为同龄人编写测试程序。 由于知道所有学生都具有相同的IDE和解释器版本,因此我决定用python编写测试程序。

我决定使用subprocess.Popen。 我将tar文件解压缩,因为我的C程序是使用tar命令存储的,然后使用gcc命令编译所需的文件。然后我使用存储在文本文件中的输入来运行测试,将用户输出与相应文本文件中的预期输出进行比较。

当我通过cmd运行我的C可执行文件时,它可以完美运行并且没有错误出现。 但是当我尝试通过subprocess.Popen运行它们时,除预期输出外,我还会收到cygwin错误 ,导致我的测试程序报告测试失败。

我使用此函数,为它提供一个字符串数组作为命令的参数。

def run_cmd_command(arguments_list):
        """
        runs the given command through the command line and returns information
        about the command.
        :param arguments_list: a list representing the command to run
        :return: A tuple containing the returncode,the output of the command and
        all the errors.
        """
        process = subprocess.Popen(arguments_list,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
        output,errors = process.communicate()
        return process.returncode,output,errors

在提供适当输入后,测试python程序即可正常工作。

另一方面,当输入不正确时,C程序应该将字符串"Invalid Input\n"打印到stderr中,但打印Invalid input 0 [main] TreeAnalyzer 1780 cygwin_exception::open_stackdumpfile: Dumping stack trace to TreeAnalyzer.exe.stackdump

我想向您提供更多信息,但是由于不了解问题的根源,因此不确定要提供哪些信息。

zsg12345 回答:通过子进程测试C程序.PYTHON中的Popen会引发cygwin错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3063445.html

大家都在问