节点 JS 生成结果:python3:无法打开文件 './test':[Errno 2] 没有这样的文件或目录

Node JS spawn result: python3: can't open file './test': [Errno 2] No such file or directory

所以我试图通过 Node JS 子进程 运行 一个名为 test.py 的简单 python 文件,但是它一直说 python3: can't open file './test': [Errno 2] No such file or directory。我尝试了一切来修复这个错误。例如,python 脚本 运行 成功地从存在 typescript 文件的同一目录中,我什至尝试了完整路径,python 文件的相对路径,但它仍然没有工作。我恳请有人也调查一下,谢谢!

test.py

    import sys
    print("hello world")
    sys.stdout.flush()
var spawn = require("child_process").spawn;
var child = await spawn("python3", ['./test.py']);
let dataMain = "";
child.stdout.on("data", (data: Buffer) => {
    // Do something with the data returned from python script
    console.log(data); // buffer data
    dataMain += data.toString();
});

child.stdout.on("end", () => {
     console.log("end");
     console.log(dataMain);
});
child.stderr.pipe(process.stderr); // prints out the error

曾与${process.cwd()}/test.py

合作