Why doesn't this C++ program execute in my code? I've got an old C++ program (not from me) which takes 2 parameters: an ascii rawInputFile.in input file and parsedOutputFile.out which contains the cleansed data from the raw inputfile. If I run the Solaris C++ program like this, it works: Solaris#> $myCPlusProg rawInputFile.in parsedOutputFile.out > aLogFile.log But if I embed it in Java as follows, throws following exception: java.lang.NullPointerException at testdeltrdlck.main(Compiled code)
Well, I don't see a class named deltrdlck here, and I also don't see how this program could throw a NullPointerException, and nothing prints "Error in command", so I suspect you're not showing us the actual code. Second, note that the "$" character demarcates shell variables, and it's exceedingly unlikely that you've got an actual binary whose name starts with a "$" -- Java isn't going to expand your shell variables for you, you'll need to use the actual name of the program!
Finally, as far as redirects go: Java is a cross-platform language, so you can't expect Runtime.exec() to understand the UNIX-specific concepts of output redirection. If you need to do this, then you can execute an instance of the shell, and tell the shell to do it -- i.e.,
Finally, note that in the command you're running, you're trying to redirect the output to a file. But then in your Java code, you're trying to read the output from the program. If the redirection succeeds, then there will be no output, right? You may need to sit and think a moment about what you actually want to do here.