Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why cant I use log files in java runtime

I have (in java),

rt.exec("qq.exe -i ..(some other parameters) > qq.log");//*1

when I run qq.exe -i ..(some other parameters) > qq.log in terminal It works fine and keeps the qq.log file correctly.

However using rt.exec (*1) doesnt work. " > qq.log" part causes problem. When I delete that part rt.exec (*1) works but I cant have qq.log file this time.

What causes this problem and Is there any soln??

like image 769
ogzylz Avatar asked Feb 12 '26 23:02

ogzylz


1 Answers

rt.exec() can't execute sh/bat code. It's just invoking another program. When you try to redirect the output stream of qq.exe with the > symbol, which is specific to shell, java doesn't understand what to do.

An alternative is when you execute some program with the exec method, get the Process returned by rt.exec(). A Process can give you an OutputStream to the application, an InputStream from the application and even an ErrorStream for a started application.

With the InputStream, you can programmatically read the result of qq.exe and all you have to do is to write this into a file.

like image 99
Colin Hebert Avatar answered Feb 15 '26 12:02

Colin Hebert