java里面调用cmd命令不起作用

win上命令

win上查询进程命令

tasklist | findstr ffmpeg

win上杀死进程命令

 taskkill -PID  pid  -F  # 后面的pid替换成查询出来的进程号

win上查看进程参数命令

wmic process where caption='ffmpeg.exe' get caption,commandline /value  # ffmpeg.exe根据实际替换

java调用时候要加cmd /c

process = Runtime.getRuntime().exec("cmd /c tasklist | findstr ffmpeg.exe");

reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

String line = null;
     while ((line = reader.readLine()) != null) {
         System.out.println(line);

reader.readLine()每次读取一行

System.out.println(line);
System.out.println(line);
System.out.println(line);
# 三次打印结果不一致,每次读取是一次迭代

System.out.println(read.lines().collect(Collectors.joining(System.lineSeparator()));

# 打印所有命令行发回内容
posted @ 2023-01-11 17:04  下个ID见  阅读(147)  评论(0)    收藏  举报