user3809938
user3809938

Reputation: 1304

unix command not working in python subprocess

The following command works fine on the shell

ssh hostname 'pgrep -fn "java -cp /strbase/apps/App"'

However not in the python subprocess, I have my array as follows

cmd_array = ['ssh', 'hostname', "'pgrep", '-fn', '"java', '-cp', '/strbase/apps/App"\'']

However I get no output.

I am trying below:

process = subprocess.Popen(
cmd_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

stdout, stderr = process.communicate()

However

stdout

evalutes to an empty string, it should give me back a number. Why is this? It works fine in the shell?

Upvotes: 0

Views: 48

Answers (1)

iElden
iElden

Reputation: 1280

Your cmd_array is wrong, you send only two argument, hostname and your command string, it's should be :

cmd_array = ["ssh", "hostname", 'pgrep -fn "java -cp /strbase/apps/App"']

Upvotes: 1

Related Questions