0

I'm attempting to return the IP address of the Windows machine into a node process using child.exec. Simple command lines seem to work but anything vaguely complex fails - anyone got any suggested resolutions / explanations for why it's failing?

Code as follows:

var exec = require('child_process').exec;
var ifconfig = (process.platform !== undefined && process.platform !== 'win32') ? 'ifconfig eth0' : 'ping -4 %COMPUTERNAME%';

var child = exec(ifconfig, function(err, stdout, stderr) {
    if (err) throw err;
    else console.log('child', stdout);
});

var FYI 'ping %COMPUTERNAME%' works, 'ping %COMPUTERNAME% -4'fails.

Also FYI, original suggestion for CLI code from here:

http://ayesamson.com/2011/06/13/get-ip-address-from-windows-command-line/

Ta

N

nick-brown
  • 31
  • 2
  • 8
  • Is there a reason why you are not using [os.networkInterfaces](http://nodejs.org/api/os.html#os_os_networkinterfaces), see http://stackoverflow.com/questions/10750303/how-can-i-get-the-local-ip-address-in-node-js – beny23 Mar 06 '13 at 10:15
  • Nope - simply didn't know about it - I knew some bright spark would suggest an alternative ;-) Having said that, I would still like to know why the code is failing for future reference. – nick-brown Mar 06 '13 at 12:09
  • Your code worked fine on my machine. Using Windows 8 64-bit. – user568109 Mar 06 '13 at 13:35
  • Thanks user - very interesting - I'm running Win7 X64. I don't suppose you have Powershell installed do you (I don't)? – nick-brown Mar 06 '13 at 14:20

0 Answers0