nodejs fs.openSync()带有'a'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:~$
这是我调用的生成图像和发布tweet的主要函数:
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",...)
相关文章:
- 如何在不同的java程序中捕获JS可变值
- 如何使用Java程序在浏览器中操作文本字段
- 如何在Java程序中读取JavaScript输出文本
- Java 程序文本文件问题
- 在java程序中执行phantomjs脚本
- 如何在Java程序中包含JavaScript文件
- 使用 JavaScript 可视化 Java 程序
- 在网站中添加基本Java程序
- java程序可以作为网页javascript和数据库之间的中介吗
- 如何将java程序连接到JSP页面
- 如何通过web界面更改java程序的变量值
- 从java程序执行java脚本中的phantom.exit()
- 用于简单java程序的Javascript包装器
- 对脚本提取的建议用java程序标记java脚本
- nodejs fs.openSync()带有'a'Java程序运行失败
- 如何请求用户输入文件位置,以便在Eclipse(Java)程序中使用和读取它
- 将JSON数据从JavaScript发送到服务器上的Java程序
- 我的Java程序将如何处理JS文件来提取函数名
- 在哪里安装 Java 程序中使用的导入模块
- 如何在云计算中实现Java程序?