簡體   English   中英

帶有標志“a”的 nodejs fs.openSync() 無法運行 java 程序

[英]nodejs fs.openSync() with the flags 'a' fails to run java program

我制作的 Twitter Bot 出現問題,涉及一個處理 Java 程序以動態生成圖像,並在 EC2 服務器上運行:在成功工作數天后,我開始從終端收到以下錯誤消息,因為沒有圖像不再由程序生成。

想知道如何解決這個問題並使我的機器人重回正軌。 有什么建議嗎?

 fs.js:432 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: ENOENT, no such file or directory 'postcards/output.png' at Object.fs.openSync (fs.js:432:18) at Object.fs.readFileSync (fs.js:286:15) at processing (/home/ubuntu/bot.js:141:29) at ChildProcess.exithandler (child_process.js:641:7) at ChildProcess.EventEmitter.emit (events.js:98:17) at maybeClose (child_process.js:743:16) at Socket.<anonymous> (child_process.js:956:11) at Socket.EventEmitter.emit (events.js:95:17) at Pipe.close (net.js:466:12) ubuntu@ip-172-31-46-35:~$

這是我調用的主要函數來生成我的圖像並發布推文:

 var exec = require('child_process').exec; var fs = require('fs'); function tweetIt(txt) { //Making this program launch processing sketch and execute it // I just need to use node to invoke this file in the terminal $ node bot.js //var cmd = 'processing-java --sketch=`pwd`/postcards --run'; var cmd = 'postcards/postcards'; exec(cmd, processing); // command to execute the sketch and callback function to call when done function processing() { var filename = "postcards/output.png"; var params = { encoding: 'base64' } var b64content = fs.readFileSync(filename, params); T.post('media/upload', { media_data: b64content }, uploaded); // just uplading my image to twitter before being able to tweet it console.log("done with the image!"); function uploaded(err, data, response) { // this is where the tweet including the image happens var id = data.media_id_string; var tweet = { status: txt, media_ids: [id] } T.post('statuses/update', tweet, tweeted); // type, params, callbackfunction } function tweeted(err, data, response) { if (err) { console.log(err); } else { console.log("It works!"); } } } }

路徑有問題? 嘗試使用 __dirname 的相對路徑(當前文件的路徑)

fs.readFile(__dirname+"/../myfolder/picture.png",...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM