2016-05-12 7 views
0

Ich benutze NWJS, um eine einfache Desktop-App zu erstellen. Ich muss console C++ app verbinden, wenn ich ein click-Ereignis in einer Schaltfläche auf html5 mache. Ich habe gehört, dass es möglich ist, das interne Modul 'child_process' von Nodejs zu verwenden. Ich habe die EXE-Datei nicht ausgeführt, wenn ich auf die Schaltfläche klicke.Wie führe ich eine .exe-Datei von Node.js

Ich habe nächsten Code:

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); 
    } 
}); 

Die EXE-Datei hat einen Eingangsparameter (eine Zahl) und es gibt einen einfachen Text mit der eingeführten Anzahl. Kann mir jemand helfen?

Danke!

+0

Mögliche doppelte versuchen geben: http://stackoverflow.com/questions/19762350/execute-an-exe-file-using-node -js – Nonemoticoner

+0

Ich denke, dass dup die Frage beantwortet, obwohl das Ziel in C++ geschrieben wurde, ist dies keine C++ Frage. – Niall

+0

Sie haben Recht! Ich werde das jetzt bearbeiten –

Antwort

0

Ich denke, man sollte dies ein

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> 
Verwandte Themen