Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:37:35+00:00 2026-06-14T17:37:35+00:00

If I use shell: ps -eaf | grep groovy I can get such output:

  • 0

If I use shell:

ps -eaf | grep groovy

I can get such output:

[root@test www]# ps -eaf | grep groovy
root       924   539  1 03:15 pts/0    00:00:05 /usr/java/jdk1.6.0_31/bin/java -classpath
/root/dev/groovy-1.8.8/lib/groovy-1.8.8.jar -Dscript.name=./groovysh -Dprogram.name=groovysh 
-Dgroovy.starter.conf=/root/dev/groovy-1.8.8/conf/groovy-starter.conf 
-Dgroovy.home=/root/dev/groovy-1.8.8 -Dtools.jar=/usr/java/jdk1.6.0_31/lib/tools.jar
org.codehaus.groovy.tools.GroovyStarter --main org.codehaus.groovy.tools.shell.Main 
--conf /root/dev/groovy-1.8.8/conf/groovy-starter.conf --classpath .
root      1127   562  0 03:20 pts/1    00:00:00 grep groovy
[root@test www]#

But if I run this command in groovy:

proc = "ps -eaf | grep groovy".execute()

proc.waitFor()  // => return 1

proc.in.text  // => return ""

proc.err.text  // => see following

The proc.err.text will be the document of ps command:

ERROR: Garbage option.

********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given

But if I run ps -eaf it will be correct.

It seems | can’t be used, is it true? How to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:37:36+00:00Added an answer on June 14, 2026 at 5:37 pm

    Yeah, you can’t use shell output piping and redirection like that.

    One option is to do:

    Process ps = 'ps -eaf'.execute()
    Process gr = 'grep groovy'.execute()
    
    Process all = ps | gr
    
    println all.text
    

    The other is to wrap it in a new shell using the List form of execute:

    println( [ 'sh', '-c', 'ps -eaf | grep groovy' ].execute().text )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use shell parameter extension in a Makefile? I need to get
To get the logcat from an Android device, I use adb shell logcat (also
I use shared hosting so I can't access to shell. I have CronsController and
Can anyone show me, how to use shell command result in Perl script ?
Usually I use shell command time . My purpose is to test if data
How can I use shell one-liners and common GNU tools to concatenate lines in
Hi I know I can use power shell or central admin to backup SharePoint
I use simple shell script to test some http server that process POST requests.
I wonder if it's possible to use a shell command output as an option
If I try to use the shell I get this API conflict. /home/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg-tmp/_mysql.so:6: RuntimeWarning:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.