The Java Execution Shell command has not been used before, and it is thought to be as convenient as C, and can be done with a system function. It's not that much of a problem today. There are two ways of executing shell commands in Java:
1. Use of Processbuilder
Processbuilder pb=new processbuilder (cmd);
Pb.start ();
2. Use of runtime
Runtime.getruntime (). EXEC (CMD)
But both of these methods have a problem, such as: Ps-ef | grep-v grep commands with pipes or redirects can be faulted. We all know that using both methods to execute a command, if you have parameters to split the command into a group or list, it will be executed as a whole (error, such as "ps-e"). For |,<,>, this is not going to work either. For Linux systems, the solution is to pass the entire command as an sh parameter and use SH to execute the command.
list<string> Cmds = new arraylist<string> ();
Cmds.add ("sh");
Cmds.add ("-C");
Cmds.add ("Ps-ef | Grep-v grep ");
Processbuilder=new Processbuilder (CMDS);
Process p = Pb.start ();
Windows to replace SH cmd.exe on the line.
Ps:linux under test is available, windows you can test yourself