使用命令行应用程序。我需要允许用户通过su
我已经尝试了
var spawn = require( 'child_process' ).spawn,
ls = spawn('su');
ls.stdout.on( 'data', ( data ) => {
console.log( "stdout: ${data}" );
});
ls.stderr.on( 'data', ( data ) => {
console.log( "stderr: ${data}" );
});
ls.on( 'close', ( code ) => {
console.log( "child process exited with code ${code}" );
});
并同步:
var fs = require('fs'),
spawnSync = require('child_process').spawnSync;
spawnSync("su");
if(fs.existsSync('./command_stdout.txt')){
// process standard output from your command here
}
if(fs.existsSync('./command_stderr.txt')){
// process error output from your command here
}
但这些都没有问我提示。