java中运行bat文件怎么才能不产生dos窗口,不带闪的
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java中运行bat文件怎么才能不产生dos窗口,不带闪的相关的知识,希望对你有一定的参考价值。
java中运行一个bat文件如下:
@echo off
C:/temp/ffmpeg.exe -i rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp -qscale 0 -t 00:00:30 -y C:/temp/%1 >C:/temp/log.txt 2>&1
exit
java中调用:
String strcmd = "cmd /c start C:\\temp\\ffmpeg.bat " + savePath;
Runtime.getRuntime().exec(strcmd);
怎样才能在运行中不产生Dos窗口
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.SequenceInputStream;
public class Processing
public static void main(String[] args) throws InterruptedException
try
Process process = Runtime.getRuntime().exec("cmd");
SequenceInputStream sis = new SequenceInputStream(process.getInputStream(), process.getErrorStream());
InputStreamReader isr = new InputStreamReader(sis, "GBK");
BufferedReader br = new BufferedReader(isr);
// next command
OutputStreamWriter osw = new OutputStreamWriter(process.getOutputStream());
BufferedWriter bw = new BufferedWriter(osw);
bw.write("cd /d d:/我的文档/桌面");
bw.newLine();
bw.write("ffmpeg -help");
bw.newLine();
bw.flush();
bw.close();
osw.close();
// read
String line = null;
while (null != (line = br.readLine()))
System.out.println(line);
process.destroy();
br.close();
isr.close();
catch (IOException e)
e.printStackTrace();
Runtime.getRuntime().exec("cmd.exe /C start /b D:\\test.bat"); 参考技术B
https://zhidao.baidu.com/question/2056499451200504427.html
引用一下别人的吧... 求采纳
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.SequenceInputStream;
public class Processing
public static void main(String[] args) throws InterruptedException
try
Process process = Runtime.getRuntime().exec("cmd");
SequenceInputStream sis = new SequenceInputStream(process.getInputStream(), process.getErrorStream());
InputStreamReader isr = new InputStreamReader(sis, "GBK");
BufferedReader br = new BufferedReader(isr);
// next command
OutputStreamWriter osw = new OutputStreamWriter(process.getOutputStream());
BufferedWriter bw = new BufferedWriter(osw);
bw.write("cd /d d:/我的文档/桌面");
bw.newLine();
bw.write("ffmpeg -help");
bw.newLine();
bw.flush();
bw.close();
osw.close();
// read
String line = null;
while (null != (line = br.readLine()))
System.out.println(line);
process.destroy();
br.close();
isr.close();
catch (IOException e)
e.printStackTrace();
参考技术D 加上/b就行了
String strcmd = "cmd /c start /b C:\\temp\\ffmpeg.bat " + savePath;
如何使批处理BAT文件在后台运行而不显示DOS窗口
%1 start mshta vbscript:createobject("wscript.shell").run("""%~0"" ::",0)(window.close)&&exit以上代码加在脚本开头行,运行后即可隐藏,但稍微会闪一下黑窗口。
参考技术A 使用wincmd 的EXEC 命令。可以隐藏DOS框。以上是关于java中运行bat文件怎么才能不产生dos窗口,不带闪的的主要内容,如果未能解决你的问题,请参考以下文章
请问怎么才能运行bat批处理文件的时候不显示DOS命令窗口?连闪一下都不要。