从节点的 child

编程入门 行业动态 更新时间:2024-10-03 21:18:00

从<a href=https://www.elefans.com/category/jswz/34/1771452.html style=节点的 child"/>

从节点的 child

我的 Windows 路径变量中存储了很多可执行文件,但我似乎无法从

spawn
child_process
方法调用。我试过没有扩展名的 .exe 文件和可执行 shell 脚本,但都失败并抛出相同的错误:

[1680300000021] FATAL (server/30780 on Odin): "uncaughtException" detected. Process will shutdown
    Error: spawn gif ENOENT
        at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
        at onErrorNT (node:internal/child_process:478:16)
        at processTicksAndRejections (node:internal/process/task_queues:83:21)

根据我从该站点上的其他问题中收集到的信息,ENOENT 错误最可能的原因是该命令不存在。

一个例外似乎是我有一个

videohashes
脚本。我将
videohashes
videohashes.exe
都放在同一个目录中,但我只称它为前者。

这些命令在我的终端上运行良好,如果有任何不同,我会从同一个终端运行我的节点应用程序。

这是我正在做的一个例子:

import { spawn } from 'child_process'

const gifProcess = spawn('gif', [`"${filePath}"`, someOtherVar])

这是有效的:

export async function getVideoHash(file: string): Promise<HashData> {
    const python = spawn('videohashes', ['-json', file])
    return new Promise(resolve => {
        let output: string = '{}'
        python.stdout.on('data', data => {
            output = (data.toString() as string)
        })
        python.on('close', () => {
            let json
            try {
                json = JSON.parse(output)
            } catch (e) {
                console.log('There was an error parsing JSON data:')
                console.log(output)
                json = {}
            }
            resolve(json)
        })
    })
}

对于我生成的几个 python 脚本,我已经求助于将完整路径作为命令传递给 python 可执行文件,因为这不起作用。我怎样才能让位于我的路径目录中的项目开始工作?

回答如下:

更多推荐

从节点的 child

本文发布于:2024-05-30 04:22:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770159.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   child

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!