B4J Question No response after a shell on raspberry

CR95

Active Member
Licensed User
I usually use "ps -ax | grep java" in a terminal to know the "java programs" running on my PI.

I try to use it inside a B4J program with a shell command
shl.Initialize("shl", "/bin/bash", Array As String("ps","-ax", "|", "grep","java"))
Execution was successful but "StdOut" was empty.

I asked to ChatGPT who answered that pipes are not allowed in shell commands
And then ChatGPT recommands to use following command
shl.Initialize("shl", "/bin/bash", Array As String("/bin/bash", "-c", "ps","-ax", "|", "grep","java"))
ChatGPT explains that the original command "ps -ax | grep java" is now "enveloped" in a command "/bin/bash -c".
Anyway, Stdout remains empty !

I guess that there is people in this forum better than ChatGPT who can say how it is easy to get the response of a simple bash command ?
I join my demo program for testing.
 

Attachments

  • TestShell.b4j.zip
    436.7 KB · Views: 41

teddybear

Well-Known Member
Licensed User
I usually use "ps -ax | grep java" in a terminal to know the "java programs" running on my PI.

I try to use it inside a B4J program with a shell command

Execution was successful but "StdOut" was empty.

I asked to ChatGPT who answered that pipes are not allowed in shell commands
And then ChatGPT recommands to use following command

ChatGPT explains that the original command "ps -ax | grep java" is now "enveloped" in a command "/bin/bash -c".
Anyway, Stdout remains empty !

I guess that there is people in this forum better than ChatGPT who can say how it is easy to get the response of a simple bash command ?
I join my demo program for testing.
ps is a separate command not in bash and you cannot use ‘|’ and grep as parameters.
Do shl.Initialize("shl", "/bin/ps", Array As String("-ax")) and parse stdOut to get java process.
 
Upvote 0
Top