2016-05-12 28 views
0

im NWJSを使用して簡単なデスクトップアプリケーションを作成する。 html5のボタンでクリックイベントを行うと、コンソールC++アプリケーションに接続する必要があります。 Nodejsの 'child_process'内部モジュールを使用することが可能だと聞きました。私はボタンをクリックするとEXEファイルをexecすることはできませんでした。Node.jsから.exeファイルを実行する方法

は、私は次のコードを持っている:

const exec = require('child_process').execFile; 
var cmd = 'Test.exe 1'; 

exec(cmd, function(error, stdout, stderr) { 
    // command output is in stdout 
    console.log('stdout:', stdout); 
    console.log('stderr:', stderr); 
    if (error !== null) { 
     console.log('exec error:', error); 
    } 
}); 

.exeファイルは、入力パラメータ(番号)を持ち、それが導入された番号を持つ単純なテキストを返します。 誰でも私を助けることができますか?

ありがとうございます!

+0

可能な重複:http://stackoverflow.com/questions/19762350/execute-an-exe-file-using-node -js – Nonemoticoner

+0

ターゲットがC++で書かれているにもかかわらず、dupがその質問に答えると思いますが、これはC++の質問ではありません。 – Niall

+0

あなたは正しいです!私は今それを編集します –

答えて

0

は、私はあなたが、これは試してみるべきだと思い

child_process.execFile(file[, args][, options][, callback]) 

file <String> The name or path of the executable file to run 
args <Array> List of string arguments 
options <Object> 

    cwd <String> Current working directory of the child process 
    env <Object> Environment key-value pairs 
    encoding <String> (Default: 'utf8') 
    timeout <Number> (Default: 0) 
    maxBuffer <Number> largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200\*1024) 
    killSignal <String> (Default: 'SIGTERM') 
    uid <Number> Sets the user identity of the process. (See setuid(2).) 
    gid <Number> Sets the group identity of the process. (See setgid(2).) 

callback <Function> called with the output when process terminates 

    error <Error> 
    stdout <String> | <Buffer> 
    stderr <String> | <Buffer>