由NodeJS产生的Java进程中的networking接口的IP地址

NodeJS启动的Java进程似乎没有检测到networking接口的IPv6地址。 考虑下面的java代码:

public class ListAddresses { public static void main(String args[]) throws SocketException { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) displayInterfaceInformation(netint); } static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { out.printf("Display name: %s\n", netint.getDisplayName()); out.printf("Name: %s\n", netint.getName()); Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { out.printf("InetAddress: %s\n", inetAddress); } out.printf("\n"); } } 

如果我从命令行运行它,它会打印以下内容:

 Display name: wlan0 Name: wlan0 InetAddress: /fe80:0:0:0:6e88:14ff:fe67:8130%3 InetAddress: /192.168.1.102 Display name: lo Name: lo InetAddress: /0:0:0:0:0:0:0:1%1 InetAddress: /127.0.0.1 

如果我从NodeJS里面这样启动它:

 var spawn = require('child_process').spawn; var prc = spawn('java', ['ListAddresses']); prc.stdout.on('data', function (data) { console.log('' + data); }); 

那么它的输出是:

 Display name: wlan0 Name: wlan0 InetAddress: /192.168.1.102 Display name: lo Name: lo InetAddress: /127.0.0.1 

所以IPv6地址丢失了。 最后,如果我改变这种方式:

 var prc = spawn('java', ['ListAddresses'], { stdio: [ 'ignore', null, null] }); 

然后,启动的java进程正确地打印所有的IP地址(这似乎与https://stackoverflow.com/a/22950304/594406有关,但我不明白这是怎么回事)。 有人有一个想法是怎么回事? 我在Ubuntu 14.04.3 LTS上使用java 1.8.0_66和node v4.2.2 。 请注意,父NodeJS进程检测IPv6地址,如果我启动一个NodeJS的孩子,那么也检测到它们。