最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to create a Child process as a specific user with Node? - Stack Overflow

programmeradmin2浏览0评论

I want to use a child process to execute a Java file. The problem I do not want this code to only have read and write permissions in a specific folder. So I was thinking of executing the code as specific user. Is this possible with node?

Here is the basic code I have:

var exec = require('child_process').exec, child;

exec("javac user_script/test.java&&java -classpath user_script test", function (error, stdout, stderr) {
    console.log(stdout);
});

I am working on a mac, but I can also run the code on ubuntu.

By the way, I know that even if this can be done it will still have security issues if the file is written by a user. But this is not what I am asking for :)

I want to use a child process to execute a Java file. The problem I do not want this code to only have read and write permissions in a specific folder. So I was thinking of executing the code as specific user. Is this possible with node?

Here is the basic code I have:

var exec = require('child_process').exec, child;

exec("javac user_script/test.java&&java -classpath user_script test", function (error, stdout, stderr) {
    console.log(stdout);
});

I am working on a mac, but I can also run the code on ubuntu.

By the way, I know that even if this can be done it will still have security issues if the file is written by a user. But this is not what I am asking for :)

Share Improve this question asked Aug 1, 2015 at 9:47 Paul FournelPaul Fournel 11.2k9 gold badges42 silver badges70 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can set the user identity (uid) of the process as specified here in the node docs. For example:

var exec = require('child_process').exec, child;

exec("javac user_script/test.java&&java -classpath user_script test", {uid: 501}, function (error, stdout, stderr) {
    console.log(stdout);
});
发布评论

评论列表(0)

  1. 暂无评论