我正在尝试运行“噩梦”脚本,使用以下代码进行屏幕截图:“usr.dir”包含直到“\ src \ ....”的路径。
String root = System.getProperty("usr.dir");
String screenshotJS = "node " + root + "\\src\\main\\resources\\screenshot.js";
try {
File tempFile = File.createTempFile(root, ".png");
Process p = Runtime.getRuntime().exec(screenshotJS + " " + url + " " + tempFile.toString());
p.waitFor();
int exitCode = p.exitValue();
if (exitCode != 0) {
System.out.println("Error Execute when exitCode=1");
}else{
System.out.println("Fine Execute when exitCode=0");
}
BufferedImage bufferedImage = new BufferedImage(
500, 500, BufferedImage.TYPE_INT_RGB );
File outputfile = new File(tempFile.getName());
ImageIO.write(bufferedImage, "png", outputfile);
return tempFile.getName();
噩梦剧本:
const nightmare = require('nightmare')();
nightmare
.goto(process.argv[2])
.viewport(1152, 864)
.screenshot(process.argv[3] || 'screenshot.png')
.end(() => {});
这个过程的回报值是1.我做错了什么?有人可以帮助我这个案子吗?
谢谢,
走了
在我运行npm i nightmare
后问题得到了解决