Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to execute child process #373

Open
PeterTran4 opened this issue Mar 13, 2024 · 1 comment
Open

Unable to execute child process #373

PeterTran4 opened this issue Mar 13, 2024 · 1 comment

Comments

@PeterTran4
Copy link

Hi all, I've been attempting to execute this child process but after much research on both the github and Stackoverflow, still stumped.

Here is my code that is throwing an error.

const officeToPdfPath = 'C:\\\\Users\\ptran\\Desktop\\expressTesting\\OfficeToPDF.exe';
const uploadsPath = 'C:\\\\Users\\ptran\\Desktop\\expressTesting\\uploads';
let command;
let outputName =  currentDate.getTime() + "converted.pdf"
command = `${officeToPdfPath} ${uploadsPath}\\${filename} ${uploadsPath}\\${outputName}`;
return new Promise((resolve, reject) => {
        exec(command, (error, stdout, stderr) => {
          if (error) {
            console.log(error);
            reject(error);
            return;
          }
          if (stderr) {
            console.log(stderr);
            reject(new Error(stderr));
            return;
          }
          else if (stdout) {
            console.log(stdout + "GOOD PDF");
          }
          console.log("Resolve Now");
          console.log(uploadsPath, outputName)
          resolve(uploadsPath + outputName);
});

This is not the full code but seems like the issue is within the exec itself.

My error:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Command failed: C:\\Users\ptran\Desktop\expressTesting\OfficeToPDF.exe C:\\Users\ptran\Desktop\expressTesting\uploads\file-1710368425793.docx C:\\Users\ptran\Desktop\expressTesting\uploads\1710368425806converted.pdf

    at ChildProcess.exithandler (node:child_process:422:12)
    at ChildProcess.emit (node:events:518:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 3,
  killed: false,
  signal: null,
  cmd: 'C:\\\\Users\\ptran\\Desktop\\expressTesting\\OfficeToPDF.exe C:\\\\Users\\user\\Desktop\\expressTesting\\uploads\\file-1710368425793.docx C:\\\\Users\\ptran\\Desktop\\expressTesting\\uploads\\1710368425806converted.pdf'
}

Node.js v20.11.1

I've double checked as well to make sure that the user is an admin and running both the service as "Local System account"..."allow Service to interact with desktop" and Using a local admin account as well.

@coreybutler
Copy link
Owner

Is exec coming from require('child_process')? If so, that is an async function running within a promise. You either need to await/return that promise, or consider using execSync instead. Otherwise it's creating a race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants