Run Java program into another Program [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-02 08:34:17

Try to add missing .jar:

Runtime run=Runtime.getRuntime();            
run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012");

... and you have to consume the process output... Like this:

InputStream in = run.getInputStream();
InputStream err = run.getErrorStream();

If you want to invoke the java class/functions from another class means, make it as jar and add the jar into your projects build path. In another class you create object of the Jared class and invoke the function. (make sure your class and function is public access)

May be you forgot to type .jar

run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012"); 
Doug

The Runtime.exec(...) methods returns a java.lang.Process instance. Just call its getInputStream() method.

Process p = run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012");
InputStream is = p.getInputStream();
cyriel

If you want just write output to some file without modifying it you can just add:

> somefile.txt

at the end of the 'command':

run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012 > somefile.txt");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!