I hae been trying to run some arguments in the cmd through java and it isn't giving me any errors. I know it is opening cmd and it executes the last argument to create the file. The only problem is that the output is not writed into the file. If I run the same exact line directly in the cmd it works perfectly. I'm just alittle stumped why it is doing what its doing

Thanks

try {

       String[] commands = {"C:/CohMetrix2007/Data/ParseIT.exe ","C:/CohMetrix2007/Data/EN/ ", "-P ", "C:/CohMetrix2007/Data/EN/sometxt ", ">C:/CohMetrix2007/Data/EN/second "};
        Runtime rt = Runtime.getRuntime();
        
       Process p = rt.exec("cmd.exe", commands);  

      }

pkollmyr
Godspeed

Since you are using Runtime.exec() to execute it, the standard output is already redirected to the parent process, which is probably why nothing is getting written. Take a look at the Process API for info on handling that output. You should be able to just get the output as a stream(the method is actually called getInputStream() because it's an input stream to your program from the output stream of the process - a little bit confusing in name) and write that to a file with a BufferedWriter.

When I tried to use buffered reader I could tell it was working because it would print out "Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp."

and then it would hang up there. any suggestions?

Thanks.

This article has been dead for over six months. Start a new discussion instead.