Executing awk command in java

后端 未结 1 1654
一向
一向 2021-01-21 21:20

i am trying to execute awk command in java for linux/unix os but the thing is when i execute the command it does not show any error it.But after execution there is no output and

1条回答
  •  温柔的废话
    2021-01-21 22:14

    Starting command line processes correctly with Java isn't easy. I suggest you use commons-exec instead of trying it yourself.

    Now you have two things in the command line which need special handing:

    • Single quotes around the AWK script. When you pass each argument as a individual strings to CommandLine via addArgument, you don't need the quotes anymore.

    • The output redirection.

      Since you create a child process, you are in control of stdin and stout. That means you need to open the target file for append in Java, wrap it in a PumpStreamHandler and pass that to DefaultExecutor. See this question for details: Process output from apache-commons exec

    0 讨论(0)
提交回复
热议问题