문제

I am trying to use following command.

Runtime.getRuntime().exec("netsh -c interface dump > c:\\location1.txt");

But it produces no output.

I know we have to separate command and its arguments i tried but still failed.

I used following way.

Runtime.getRuntime().exec("netsh",new String[] "-c", "interface", "dump >", "c:\\location1.txt");

But still produces no output.

If anyone knows how to use all or some of the NETSH commands using runtime then it will be great helpful.

도움이 되었습니까?

해결책

You can try using ProcessBuilder

ProcessBuilder pb=new ProcessBuilder(command);
pb.redirectErrorStream(true);
Process process=pb.start();
BufferedReader inStreamReader = new BufferedReader(
    new InputStreamReader(process.getInputStream())); 

while(inStreamReader.readLine() != null){
    //do something with commandline output.
}

다른 팁

This is netshon Windows ? Try to specifi full path to executable:

Runtime.getRuntime().exec("C:/full/path/netsh.exe",...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top