tags:

views:

50

answers:

2

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??

A: 

You must invoke CMD.EXE with appropriate switches for this to work as you intend it to.

Thorbjørn Ravn Andersen
+3  A: 

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.

Colin Hebert
thnx a lot. Minor correction: it is not OutputStream, it is InputStream. Outputs of programs go into InputStream. OutputStream is our outputs going into the program...
ogzylz