pythonrpyc

how to get the output of a command via rpyc?


I need to run a command via rpyc and get the result of this command.

But whenever I run the command, it is printed on the remote server and can not bring the result.

What I am doing is the following:

import os, sys
import rpyc

conn = rpyc.classic.connect('server_remote')
a = conn.modules.os.system( "ls -lh")

print a

The output of my command is 0 for any command I run.

python get_output.py
0

Solution

  • Use os.popen or subprocess.checked_output instead of system. System just returns the exit code, while the output is printed to your stdout (i.e. you don't get hold of it programmatically)