node.js - Node 失败退出代码 1

标签 node.js npm photoshop child-process photoshop-script

我正在尝试使用以下代码通过 childprocess execsync 运行 photoshop 脚本,但出现错误

try {
    const child_process = require("child_process")
    child_process.execSync('"C:/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe" Z:/myfile.jsx', (err, stdout, stderr) => {
        if (err) {
            console.log("error here");
        }
    })
        .on('close', function (code, signal) {console.log('go to next step')})
} catch (err) {
    err.stdout;
    err.stderr;
    err.pid;
    err.signal;
    err.status;
}

但是我得到一个错误

{ Error: Command failed: "C:/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe" Z:/Render2.0/psTextConvertor.jsx
    at checkExecSyncError (child_process.js:611:11)
    at Object.execSync (child_process.js:648:13)
    at startPhotoshop (Z:\Render2.0\tempsqs.js:422:23)
    at mergeFontData (Z:\Render2.0\tempsqs.js:410:9)
    at ChildProcess.<anonymous> (Z:\Render2.0\tempsqs.js:282:21)
    at ChildProcess.emit (events.js:187:15)
    at ChildProcess.EventEmitter.emit (domain.js:442:20)
    at maybeClose (internal/child_process.js:962:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
  status: 1,
  signal: null,
  output: [ null, <Buffer >, <Buffer > ],
  pid: 5492,
  stdout: <Buffer >,
  stderr: <Buffer > }

但脚本运行完美,但我没有得到退出代码,请帮忙

最佳答案

我在让 Photoshop 从 Node 启动和运行脚本作为子进程时遇到了类似的问题。当时我在使用 Adob​​e CS6 的 Windows 系统上工作,并且能够通过编写一个 powershell 脚本来启动带有 args 的 photoshop 来执行 ExtendScript 文件来实现这一点,然后使用 child -process.exec 从 Node 运行该 powershell 脚本。

电源外壳:

Start-Process -FilePath  "C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Photoshop.exe" -ArgumentList "C:\Scripts\MyScript.jsx" -Wait

Node :

function runPowershell(path) {

  var spawn = require("child_process").exec, child;
  
  child = spawn(`powershell -ExecutionPolicy Bypass -File ${path} -NoExit`);
  child.stdout.on("data", function (data) {
    console.log("Powershell Data: " + data);
  });
  child.stderr.on("data", function (data) {
    console.log("Powershell Errors: " + data);
  });
  child.on("exit", function () {
    console.log("Powershell Script finished");
  });
  child.stdin.end(); //end input
}

runPowershell("path/to/powershellScript.ps1");

关于node.js - Node 失败退出代码 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53632588/

相关文章:

node.js - npm 安装完整性在不同的环境中是不同的(windows vs linux)

c# - 如何在 C# 中从 JPEG 中提取 'copyright status'

javascript - 向 MongoDB 插入数据并上传图片问题 enctype ="multipart/form-data"

javascript - 如何克服NodeJS堆内存错误?

node.js - 是否有一个 npm 命令来列出我的每个直接依赖项正在引入的依赖项数量?

node.js - Node NV : command not found while trying to create virtualenv in node

colors - 从程序员的角度来看一个 Photoshop 设计问题

actionscript-3 - 有没有办法使用 AS3 导出 PSD

apache - AWS 和 Node.js,我需要 nginx 还是 apache?

javascript - JS : Maximum call stack size exceeded on disconnect despite function being empty