在Mac上运行Popen,它用我的程序打开新的终端,尽管我给了一个带有命令的脚本,它什么也不做

2024-04-26 01:30:36 发布

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

所以我在写一个程序,为另一个程序创建输入,然后对另一个程序创建的输出做一些处理。你知道吗

现在我想用Popen来打开这个程序并用这个程序运行一个脚本。我已经有了一个在windows上运行的版本,但是我想在Mac上也执行这个版本,这就开始出现问题了。你知道吗

在Mac上,它只启动一个带有所需程序的终端,而不执行其他操作。没有错误消息,我不知道我需要在我的命令中更改什么,所以它确实做了一些事情,而不仅仅是用程序打开一个终端并忽略我的脚本。你知道吗

# This function calls polymake to execute a script with two input parameters

    console_object = subprocess.Popen(['/Applications/polymake.app/Contents/MacOS/polymake', '--script', script_filename, vertex_filename, poly_filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    stdout, stderr = console_object.communicate()
    if stderr != None:
        print(stderr)
        raise SystemExit(1) # One should not do this in a function
    if stdout != None:
        string = str(stdout).replace('\\n', '\n')[1:]
        if equalities:
            string = string.replace(">=", "=")
        print(string)
        if equalities:
            file = open(console_filename, 'a')
        else:
            file = open(console_filename, 'w')
        file.write(string[1:-1])
        file.close()
        print("\nThis output was written into %s" % console_filename)

Tags: 程序版本脚本stringifstderrstdoutscript