在Mac上运行Popen,它将打开我的程序的新终端,尽管我给脚本提供了命令,但它什么也没做

时间:2019-04-17 09:49:07

标签: python macos popen

因此,我正在编写一个程序,该程序为另一个程序创建Input,然后对其他程序创建的Output进行处理。

现在,我想使用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)

0 个答案:

没有答案