- 论坛徽章:
- 0
|
目标是实现从test1.txt中提取若干个列写入test2.txt中 代码如下
单独执行cat ./test1.txt 是没问题的,但是没法写入test2.txt中,其他几种命令都没有结果。是不是这个方法不支持awk,还是有其他什么问题?那位高人指点一下
- import gnu.getopt.*;
- import java.io.*;
- import java.util.*;
- import java.lang.*;
- public class test{
- public static void main(String argv[])
- {
- try
- {
- Process child = Runtime.getRuntime().exec("colrm 1 29 < ./test1.txt >; test2.txt");
- //Process child = Runtime.getRuntime().exec("cat ./test1.txt | awk '{print $7 $8 $9 $10 $11 $12}' >; test2.txt");
- //Process child = Runtime.getRuntime().exec("awk '{print $7 $8 $9 $10 $11 $12}' >; test2.txt");
- //Process child = Runtime.getRuntime().exec("cat ./test1.txt ");
- if (child.waitFor() == 0)
- {
- System.out.println("\r\nCreate test2" + ".txt" + " Successfully");
- }
-
- else{
- System.out.println("\r\n Failed to Create test2" + ".txt");
- failedCount++;
- }
- }catch(java.lang.Exception se)
- {
- System.out.println(" failed!");
- failedCount++;
- }
-
- } //main
- }//class
复制代码 |
|