java command execution class

There are two commonly used methods for command execution under Java:

1. Use ProcessBuilder

ProcessBuilder pb=new ProcessBuilder(cmd); 
pb.start();

2. Use Runtime

Runtime.getRuntime().exec(cmd)

It can be seen that:

The bottom layer of Runtime.getRuntime().exec() is actually ProcessBuilder .

That is to say, when the above cmd parameters are controllable, there are problems with command execution.

 

Reference link: Strange command execution under Java

Guess you like

Origin blog.csdn.net/Candyys/article/details/108509357