从节点的 child_process spawn 在我的路径变量上运行可执行文件

问题描述 投票:0回答:0

我的 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 可执行文件,因为这不起作用。我怎样才能让位于我的路径目录中的项目开始工作?

node.js environment-variables child-process spawn
© www.soinside.com 2019 - 2024. All rights reserved.