windows 下 查看进程,并杀死进程,及java调用多cmd命令

1.查看所有进程的 

wmic process  get caption,commandline /value

 

2.列举当前的进程、进程路径、命令行、进程ID、父进程ID、线程数,内存使

 

wmic process get name,executablepath,commandline,processid,parentprocessid,threadcount,workingsetsize/value

 

  3. 根据执行的文件,如python.exe 的所属的进程

wmic process where caption="python.exe" get processid,caption,commandline /value

输出
 

C:\Users\aigoes\Desktop\detection\result>wmic process where caption="python.exe" get processid,caption,commandline /value


Caption=python.exe #执行文件
CommandLine=python  detection.py   #运行的命令
ProcessId=17956 #pid


Caption=python.exe
CommandLine=E:\install\anaconda2.5\python.exe C:/Users/aigoes/Desktop/detection/tools/test.py
ProcessId=2304

4.根据cmd命令查询进程,如查询命令为python detection.py的进程

wmic process where CommandLine="python  detection.py" get processid /value

输出

ProcessId=17956

5.杀死进程

taskkill /F /PID  17956

输出

成功: 已终止 PID 为 17956 的进程。

 

6. java 连续调用cmd命令

 

如在命令1进入的目录下,跳转到目录2.使用&&来连接命令

public static void run_test(){
    	
	   	  Process process;  
	   	  String cmd="cmd /c \"c: && cd \\Users\\aigoes\\Desktop\\detection\\tools && python test.py\"";
	   
	         try {  
	             Runtime runtime = Runtime.getRuntime();  
	   
	             System.out.println("开始执行。。。");  
	             process = runtime.exec(cmd);  
	             System.out.println(cmd);
	             process.waitFor();
	   
	             //打印执行的输出结果  
	             InputStream is = process.getInputStream();  
	             InputStreamReader isr = new InputStreamReader(is, "gbk"); //gbk:解决输出乱码  
	             BufferedReader br = new BufferedReader(isr);  
	             String line;  
	             while ((line = br.readLine()) != null){  //注意,当python test.py进程执行结束才会执行输出

	                 System.out.println(line);  
	             }  
	   
	             is.close();  
	             isr.close();  
	             br.close();  
	         }catch (Exception e){  
	             e.printStackTrace();  
	         }  
	   }

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

life1024

你的鼓励将是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值