@echo off
set /a x1 = 1
set /a y1 = 2
set /a z1 = %x1% + %y1%
echo %x1% + %y1% = %z1%
set /a x2 = 4
set /a y2 = 2
set /a z2 = %x2% / %y2%
echo %x2% / %y2% = %z2%
set /a x3 = 4
set /a y3 = 2
set /a z3 = %x3% * %y3%
echo %x3% * %y3% = %z3%
set /a x4 = 5
set /a y4 = 2
set /a z4 = %x4% - %y4%
echo %x4% - %y4% = %z4%
set /a z5 = %z1% + %z2% + %z3% + %z4%
echo result=%z5%
pause
![](https://img-blog.csdnimg.cn/20210812114550369.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NwZW5jZXJfdHNlbmc=,size_16,color_FFFFFF,t_70)
@echo off
set /a x1 = 1
set /a y1 = 2
set /a z1 = %x1% + %y1%
echo %x1% + %y1% = %z1%
set /a x2 = 4
set /a y2 = 2
set /a z2 = %x2% / %y2%
echo %x2% / %y2% = %z2%
set /a x3 = 4
set /a y3 = 2
set /a z3 = %x3% * %y3%
echo %x3% * %y3% = %z3%
set /a x4 = 5
set /a y4 = 2
set /a z4 = %x4% - %y4%
echo %x4% - %y4% = %z4%
set /a z5 = %z1% + %z2% + %z3% + %z4%
echo result=%z5%
exit
package ce;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class ExeBat
{
public static void main(String[] args)
{
Process p;
String cmd = "D:\\2.bat";
try
{
p = Runtime.getRuntime().exec(cmd);
InputStream fis = p.getInputStream();
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
{
System.out.println(line);
if (line.startsWith("result"))
{
System.out.println(line.substring(line.indexOf("=") + 1));
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
![](https://img-blog.csdnimg.cn/20210812114645217.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NwZW5jZXJfdHNlbmc=,size_16,color_FFFFFF,t_70)
批处理文件参数输入以及执行