0
我想通過使用node.js的特定Twitter帳戶的推文來觸發我的樹莓派上的PIFM。然而,當我運行在命令行上twitpifm.js:錯誤:產卵sh ENOENT Node.js
node twitpifm.js
我得到以下錯誤:
events.js:141
throw er; // Unhandled 'error' event
^
Error: spawn sh ENOENT
at exports._errnoException (util.js:874:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at doNTCallback2 (node.js:439:9)
at process._tickCallback (node.js:353:17)
at Function.Module.runMain (module.js:469:11)
at startup (node.js:134:18)
at node.js:961:3
我使用這個版本PIFM對我PI2
https://github.com/asmello/fm_transmitter
我寫了一個腳本(test.sh),它將從命令行啓動PIFm,不帶參數
#!/bin/bash
/home/pi/PIFm/fm_transmitter/bin/Release/fm_transmitter music.wav 103.50
我知道我需要在我的node.js中使用child_process來激活這個shell腳本,但是遇到了麻煩;
首先,我調用子進程:
var spawn = require('child_process').spawn // child process.spawn
然後我嘗試用下面的觸發殼:
function thisTweet(){
spawn('sh', ['test.sh'], { // shell script I want to run.
cwd:' /home/pi/Desktop/Twitter', // current working directory where my twitpifm.js file is
env: Object.assign({}, process.env, { PATH: process.env.PATH + '/home/pi/PIFm/fm_transmitter' }) //this sets a path to where test.sh is
})
任何建議將是巨大的!