如何运行从Java的批处理文件? [英] how to run a batch file from java?

查看:160
本文介绍了如何运行从Java的批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想逃离我的Java codeS一个批处理文件,但不幸的是我不能
正常运行。实际上批处理文件正在运行,但只批处理文件的第一行
正在运行,所以请给解决了,这里是codeS和批处理文件。

 类巴塔
{
公共静态无效的主要(字串[] args)
{
尝试
{
 调用Runtime.getRuntime()EXEC(start_james.bat);
  }
  赶上(例外五){}
}
}

和批处理文件是

  CD \\
C:
CD C:\\ Tomcat的5.5 \\的webapps \\ mail_testing \\詹姆斯 - 2.3.2 \\ BIN
的run.bat开始


解决方案

你有什么期望 CD 办?这并不右看看我...

如果您的批处理文件,只是要运行另一个批处理文件,为什么不能运行的目标批文件开始?如果你担心的初始工作目录,使用这需要一个文件参数说要使用的目录过载。例如:

 文件DIR =新的文件(C:\\\\的Tomcat 5.5 \\\\ \\\\的webapps \\\\ mail_testing詹姆斯-2.3.2 \\\\斌);
调用Runtime.getRuntime()EXEC(start_james.bat,空,DIR)。

I am trying run a batch file from my java codes, but unfortunately I could not run it properly. Actually the batch file is running but only the first line of the batch file is running, so please give solution to it, here are the codes and the batch file.

 class bata
{
public static void main(String [] args)
{
try
{
 Runtime.getRuntime().exec("start_james.bat");


  }
  catch(Exception e) {}
}
}

and the batch file is

cd\
c:
cd C:\Tomcat 5.5\webapps\mail_testing\james-2.3.2\bin
run.bat

start

解决方案

What do you expect cd: to do? That doesn't look right to me...

If your batch file is only going to run another batch file, why not run that target batch file to start with? If you're worried about the initial working directory, use the overload which takes a File argument to say which directory to use. For example:

File dir = new File("C:\\Tomcat 5.5\\webapps\\mail_testing\\james-2.3.2\\bin");
Runtime.getRuntime().exec("start_james.bat", null, dir);

这篇关于如何运行从Java的批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆