/dev/null | tr...">

R - system commands with multiple pipes do not return stdout

bash:

ps -aux | grep -E "^.*\b[^grep](python).*(runserver).*$" 2>/dev/null | tr -s " " | cut -d " " -f 2

      

It returns the correct result. (eg.)

1450
1452

      

The same code in R

vLog <- system('ps -aux | grep -E "^.*\b[^grep](python).*(runserver).*$" 2>/dev/null | tr -s " " | cut -d " " -f 2', intern = TRUE)

      

return character(0)

+3


source to share


1 answer


Just replace \b

with \\b

and also know [^grep]

which matches any character, but not g

either r

or e

or p

.

vLog <- system('ps -aux | grep -E "^.*\\b[^grep](python).*(runserver).*$" 2>/dev/null | tr -s " " | cut -d " " -f 2', intern = TRUE)

      



Example:

> system('ps -aux | grep -E "^.*\\bpython" 2>/dev/null | tr -s " " | cut -d " " -f 2', intern = TRUE)
[1] "2519" "2526" "3285" "3291"
> system('ps -aux | grep -E "^.*\bpython" 2>/dev/null | tr -s " " | cut -d " " -f 2', intern = TRUE)
character(0)

      

+3


source







All Articles