子进程将信息传递给exe

时间:2020-02-05 06:58:12

标签: python c++ subprocess direct3d

我使用python中的子进程库来控制exe文件,以实现python与Direct3D创建的3D模型之间的交互。我以前曾经很成功,但是昨天我发现他没有任何回应。 下面是我的python代码。

import subprocess
from struct import *

proc = subprocess.Popen("C:/Users/Administrator/Documents/Visual Studio 2015/Projects/金字塔/Debug/Pyramid.exe",
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    encoding='utf-8')

state = "run"
while state == "run":
    input = "OK"

    if input == "quit":
        state = "terminate" # any string other than "run" will do

    #input = pack()
    proc.stdin.write(input+"\n")
    proc.stdin.flush()
    cppMessage = proc.stdout.readline().rstrip("\n")
    print("cppreturn message ->" + cppMessage + " written by python \n")

以下是我在C ++中d3d代码的一部分。

bool Display(float timeDelta)
{
    if (Device)
    {
        //....I I left out the irrelevant part in Display
        std::cin >> python_message;
        //rolation 
        if (python_message == "OK")
        {
            //std::cout << python_message;
            static float y = 0.0f;
            y += timeDelta * 3.0f;
            if (y >= 6.28f)
                y = 0.0f;
            D3DXMatrixRotationY(&matWorld, y);
            Device->SetTransform(D3DTS_WORLD, &matWorld);
        }
        else if (python_message == "STOP")
        {
            //std::cout << python_message;
            static float y = 0.0f;
            D3DXMatrixRotationY(&matWorld, y);
            Device->SetTransform(D3DTS_WORLD, &matWorld);
        }


        Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4);

        Device->EndScene();
        Device->Present(NULL, NULL, NULL, NULL);

    }
    return true;
}

在我的主要功能中,我循环显示功能:

d3d::EnterMsgLoop(Display);

0 个答案:

没有答案