Objective C Hello World child process permission denied

568 views
Skip to first unread message

Shaun Clark

unread,
Jan 18, 2014, 12:40:41 AM1/18/14
to node-...@googlegroups.com
I have a simple C++ app that prints "Hello World" to the console:

int main(int argc, const char *argv[]) {
// insert code here...
printf("Hello, World!\n");
}

I want to run this as a child process. So I use the code:

var terminal = require('child_process').spawn('./HelloWorld');
terminal.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
terminal.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});
terminal.on('close', function (code) {
  console.log('child process exited with code ' + code);
});

In Node-WebKit I get:
"stderr: execvp(): Permission denied\n"

in Node I get:

"stdout: Hello, World!"

Can someone point out what I'm doing wrong? I've tried exec & execFile as well, no dice on either one. Thanks!

Shaun

Shaun Clark

unread,
Jan 18, 2014, 3:02:18 PM1/18/14
to node-...@googlegroups.com
It seems to be path related, if I run it from the full path it works:

exec('/Users/username/nw-sample-apps/frameless-window/KeypressFoundation', function callback(error, stdout, stderr){
     console.log("stdout:" + stdout);
    console.log("error:" + error);
    console.log("stderr:" + stderr);
});

is there a way to get the exact path of where the app is being run from? Thanks!

Nikola Jokic

unread,
Jan 18, 2014, 3:13:08 PM1/18/14
to node-...@googlegroups.com

check here for 'process.path':

http://nodejs.org/api/process.html

Dana 18. 1. 2014. 21:02 osoba "Shaun Clark" <shaun...@synclio.com> napisala je:
--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Shaun Clark

unread,
Jan 18, 2014, 3:14:40 PM1/18/14
to node-...@googlegroups.com
Okay for anyone who runs across this problem this is how I solved it, the permissions issue is because the app is copied to another directory which makes sense, but the permissions are not maintained, so I had to chmod the permissions after copying the file, the whole thing put together looks like:

var fs = require('fs');
fs.chmodSync(process.cwd() + '/KeypressFoundation', 0777);

exec(process.cwd() + '/KeypressFoundation', function callback(error, stdout, stderr){
     console.log("stdout:" + stdout);
    console.log("error:" + error);
    console.log("stderr:" + stderr);
});

note the process.cwd() to get the right path of where the app is located. Hope this helps someone, thanks!

Marc Torruella

unread,
Jan 18, 2014, 3:27:34 PM1/18/14
to node-...@googlegroups.com

Thank you for sharing!

El dia 18/01/2014 21:14, "Shaun Clark" <shaun...@synclio.com> va escriure:
--

lukasz...@gmail.com

unread,
Aug 17, 2019, 7:54:24 PM8/17/19
to nw.js
Reply all
Reply to author
Forward
0 new messages