进程失败,退出代码为1

时间:2019-02-26 20:48:40

标签: java nightmare

我正在尝试使用以下代码来运行“噩梦”脚本,以进行屏幕截图: “ 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();

梦m脚本:

    const nightmare = require('nightmare')();
    nightmare
   .goto(process.argv[2])
   .viewport(1152, 864)
   .screenshot(process.argv[3] || 'screenshot.png')
   .end(() => {});

该过程的返回值为1。 我做错了什么?有人可以协助我处理此案吗?

谢谢

伊多

1 个答案:

答案 0 :(得分:0)

我运行npm i nightmare

后,问题解决了
相关问题