问候,
这是一个相当明确的问题。
我必须使用启动一个Java作业<java>
,该作业将与ant并行运行,因此如果该作业的寿命超过了ant进程,那是可以的spawn="true"
。
我必须在指定文件中查看作业输出。这是通过完全实现output="job.out"
了spawn="false"
,但我还挺有走出运气spawn"=true"
。
因此,是否有任何中等程度的恶意破解,或者我真的必须java
用exec
下面的类似代码包装通话吗?
CMD /C my-java-command-and-hardcoded-classpath-goes-here > job.out
谢谢,安东
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
public class StreamRedirector {
public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException,
NoSuchMethodException, InvocationTargetException, IllegalAccessException {
System.out.println(Arrays.toString(args));
// parse the arguments
if (args.length != 2) {
throw new IllegalArgumentException(
"Usage:" +
"\targ0 = wrapped main FQN;\n" +
"\targ1 = dest output file name;\n" +
"\tother args are passed to wrapped main;"
);
}
String mainClass = args[0];
String destinationFile = args[1];
// redirect the streams
PrintStream outErr = new PrintStream(new FileOutputStream(destinationFile));
System.setErr(outErr);
System.setOut(outErr);
// delegate to the other main
String[] wrappedArgs = new String[args.length - 2];
System.arraycopy(args, 2, wrappedArgs, 0, wrappedArgs.length);
Class.forName(mainClass).getMethod("main", String[].class).invoke(null, (Object) wrappedArgs);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句