0

I have a node webkit app, part of which involves using child processes in node to call pdftk (a separate command line program).

I don't want my users to have to install pdftk or use the command line, so I included pdftk in the packaged version of the node webkit app. If I run this packaged app from the command line, it works fine - and I assume that's because it's using the version of pdftk that's installed on my computer, not the one packaged with the app.

When I try to launch the app by double clicking on an icon in the gui, as I'd want a user to be able to do, I get a node.js error - child process ENOENT. I think that's because when launched through the gui, it doesn't inherit the environment variables (including PATH) from my command-line environment.

I know I can set environment variables as an option when I call the child process, but haven't been able to figure out how to do that correctly. I'm not sure what variable I should set, or what I should set it to. I suppose I'm not sure if it's even possible to call pdftk from within the packaged app, or if I would need to have the user install it on their own computer. Any help would be much appreciated.

lpappone
  • 2,755
  • 2
  • 15
  • 15

1 Answers1

0

I think this might not be about environment variables. I guess when you run from the command line your current working directory (CWD) is where the app is. And I think you set the path to pdftk relative to the node script. When you double click (a shortcut) the current working directory and the path where the node script is located are different so relative paths don't work as expected.

When you use relative paths, always use __dirname to get the path the node script is on and use it to set path to the pdftk file. The path.resolve function can be useful when doing this. Read path.resolve documentation

I strongly recommend you to check this question and answers

Community
  • 1
  • 1
Thanish
  • 309
  • 2
  • 5