简体   繁体   English

如何向 node.js 上的 pdb 发送消息?

[英]How to send messages to pdb on node.js?

I'm trying to write a node.js application that features a Python debugger GUI.我正在尝试编写一个具有 Python 调试器 GUI 的 node.js 应用程序。 Currently, I'm have a node.js application that calls a Python file with a pdb.set_trace().目前,我有一个 node.js 应用程序,它使用 pdb.set_trace() 调用 Python 文件。 I'm able to use node.js to spawn a child process, but I'm not really sure how to make node.js send a child message.我可以使用 node.js 生成子进程,但我不确定如何让 node.js 发送子消息。

Currently, I have spawned a child program here in a post section in node.js: `目前,我在 node.js 的帖子部分生成了一个子程序:`

pyProg = spawn('python', ['test-submission-'+req.body.userID+'.py', testCase, "debug"], {stdio: ["pipe","pipe","pipe"]});

pyProg.stdout.on('data', function(data) {
        res.write("\n\nOUTPUT:\n")
        res.write(data);
        res.end('\nDEBUG');
});

` This correctly spawns the child and node.js tells the frontend that pdb has started. ` 这正确地生成了子进程并且 node.js 告诉前端 pdb 已经启动。

Now, to communicate with pdb, I have written the following post section: `现在,为了与 pdb 通信,我编写了以下帖子部分:`

router.post('/sendDebugMSG', function(req, res)  {
    console.log("Sending debug message: " + req.body.message);
    pyProg.stdin.write(req.body.message);
    pyProg.stdout.on('data', function(data) {
        res.write("\n\nOUTPUT:\n");
        res.write(data);
        res.end('\nDEBUG');
    });
    pyProg.stderr.on('data', function(data) {
        dataStr = data.toString();
        res.write("\n\nOUTPUT:\n")
        res.write(data);
        res.end('\nFAILED TO EXECUTE');
        // res.send("FAILED:" + dataStr);
        // res.end('end');
    });
});

When the frontend sends in the message "next", the only thing that outputs is当前端发送消息“next”时,唯一输出的是

Sending debug message: next

Does anyone know how to make node.js communicate with pdb?有谁知道如何让 node.js 与 pdb 通信?

It turns out I needed a \n appended to the next command.事实证明,我需要在下一个命令后附加一个 \n。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM