节点失败退出代码1

3
我正在尝试通过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 > }

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


我尝试使用exec而不是execSync,但仍然遇到相同的问题。 - madha kumar
1个回答

0
我曾经遇到过类似的问题,即在Windows系统上使用Adobe CS6时,无法从node作为子进程启动Photoshop并运行脚本。最终我通过编写powershell脚本来解决这个问题,该脚本可以使用参数启动Photoshop并执行ExtendScript文件,然后再从node中使用child-process.exec运行该powershell脚本。
Start-Process -FilePath  "C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Photoshop.exe" -ArgumentList "C:\Scripts\MyScript.jsx" -Wait

节点:

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");


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接