gpt4 book ai didi

node.js - Node 使用 child_process 启动 VLC Player

转载 作者:太空宇宙 更新时间:2023-11-04 01:37:32 31 4
gpt4 key购买 nike

我有一个 POST 函数,我尝试使用 child_process 启动 VLC 播放器。我正在使用最新的 Raspbian 版本。

router.post('/', function (req, res) {
let spawn = require('child_process').spawn;
let vlc = spawn('vlc');
vlc.stderr.on('data', function(data) {
console.log(data.toString());
});
vlc.on('exit', function(code){
console.log('Exit code: ' + code);
});
res.send({success: true})
});

触发请求后,我收到此消息:

VLC is not supposed to be run as root. Sorry. If you need to use real-time priorities and/or privileged TCP ports you can use vlc-wrapper (make sure it is Set-UID root and cannot be run by non-trusted users first).

由于 VLC 无法以 root 身份运行,因此我将 UID 参数添加到 vlc 启动脚本中,现在看起来像这样:

let vlc = spawn('vlc' ,{uid: 1000});

其中UID:1000是我一直使用的用户的ID。

触发请求后,我在日志中收到另一条消息:

[016f9960] main libvlc error: cannot open config file (/root/.config/vlc/vlcrc): Permission denied

Home directory not accessible: Permission denied

[01762eb0] vlcpulse audio output error: PulseAudio server connection failure: Connection refused

[0176bde8] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

[0176bde8] main interface error: no suitable interface module [016f9960] main libvlc error: interface "dbus,none" initialization failed

[0176c7a8] main interface error: no suitable interface module [016f9960] main libvlc error: interface "globalhotkeys,none" initialization failed

[016f9960] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.

error: XDG_RUNTIME_DIR not set in the environment.

[0176c7a8] skins2 interface error: cannot initialize OSFactory

[017614e0] main playlist: playlist is empty

[0176c7a8] [cli] lua interface: Listening on host "*console".

玩家没有运行。但如果我通过 ssh 运行相同的命令,它就会运行。什么可能导致 Node 无法运行?

最佳答案

问题是我的服务器正在使用

运行

nodemon

我确实尝试了一切,然后当我准备放弃时,我不小心使用 node 命令以正常方式启动了服务器。 VLC 正在启动,没有任何错误。我不必在参数中传递任何用户 ID。它工作得很好,就像这样:

let spawn = require('child_process').spawn;
let vlc = spawn('vlc');

我真的很好奇为什么 nodemon 会导致这种行为。

关于node.js - Node 使用 child_process 启动 VLC Player,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54058502/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com