0

I am running following unix command using ProcessBuilder and it is working fine.

String[] commands = {"egrep","search string","fileName"} ProcessBuilder pb =...

Now I have an additional requirement to filter the output.

String [] commands = {"egrep","search string","fileName","|","awk\'$0 >\"time\" && $2==\"INFO\"\'"}

I am getting error "IO Exception: No such file error". It seems it is considering pipe(|) and other awk command as file.

I also tried adding prefix "bash -c" or "/bin/sh -c" like

String [] commands = {"bash","-c","egrep","search string","fileName","|","awk\'$0 >\"time\" && $2==\"INFO\"\'"}

Now I am getting error "bash -c line0: syntax error near unexpected token 'is'bash:-c line0:"

I also tried giving entire egrep command in single string but it also didn't work.

Please advice what am I missing error to use pipe for filtering the output.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
user1986187
  • 21
  • 1
  • 3

1 Answers1

0

Without considering whether your proposed egrep/awk command line will work - I'm unsure it's what you intend - consider making the full command line a single argument to the -c option of bash, so you'll have only three strings involved in the construction of the ProcessBuilder. See SO question 3776195 for some more info.

Community
  • 1
  • 1
sjnarv
  • 2,334
  • 16
  • 13