0

I have the following python script which is trying to get file count in every sub-directory under the given path , but it gives no output :

#!/usr/bin/env python3.5

import subprocess
import os

command=r'ssh <some-server> "(echo \"import os\" ; echo \"for r,d,f in os.walk(\"/home/vibhora/\"): print (r,len(f))\")| python"'
ssh = subprocess.Popen(["bash", "-c", "{0}".format("command")], stdout=subprocess.PIPE)
out = ssh.stdout.read().decode('utf-8')
print(out)

Anybody has any idea what Am I doing wrong here ? Any better approach to get the file list are most welcome , Thanks in advance.

CristiFati
  • 38,250
  • 9
  • 50
  • 87

1 Answers1

1

You are using "command" instead of command.

ssh = subprocess.Popen(["bash", "-c", "{0}".format(`command`)], stdout=subprocess.PIPE`, stderr=subprocess.STDOUT`)
123
  • 10,778
  • 2
  • 22
  • 45
hailinzeng
  • 966
  • 9
  • 24