Fabric run() output is dirt

262 Views Asked by At

When I use:

out = run("ls") 

I want in "out" list of files. But, I also get trash. How to get only out of the shell command?

$ fab -p 111 -H server func
[server] Executing task 'func'
[server] run: ls
[server] out:
[server] out:
[server] out: MQSI 9.0.0.3
[server] out: /opt/IBM/mqsi/9.0.0.3
[server] out:
[server] out: /var/mqsi/odbc/odbc64.ini
[server] out: file1 file2 file3
[server] out:

MQSI 9.0.0.3
/opt/IBM/mqsi/9.0.0.3

/var/mqsi/odbc/odbc64.ini
file1 file2 file3

So in out i get all text from MQSI to file3. But I need only file1 file2 file3

Probably it is not fabric fault. Maybe something with server shell.

I very tried use different fabric hiding, but didn't find the answer.

1

There are 1 best solutions below

1
On BEST ANSWER

If I understand correctly, by "trash" you're referring to the "\t", "\r", and "\n" characters that are present in the output of the ls command. An example I just generated looks like this:

>>>> out = run('ls')
>>>> print(out)
'nginx\t\t\t\tnginx.bak.20151206-2209.tar.gz\tnginx.bak.20151206-2258.tar.gz\tphp-fpm.conf.save\r\nnginx.bak.20151206-2047.tar.gz\r\nnginx.bak.20151206-2153.tar.gz\tnginx.bak.20151206-2226.tar.gz\tphp-fpm.conf\t\t\tsupervisord.conf\r\nnginx.bak.20151206-2206.tar.gz\tnginx.bak.20151206-2255.tar.gz\tphp-fpm.conf.default\t\tvarnish'

To turn that into a list, you can .split() it, like:

>>> out.split()
['nginx', 'nginx.bak.20151206-2209.tar.gz', 'nginx.bak.20151206-2258.tar.gz', 'php-fpm.conf.save', 'nginx.bak.20151206-2047.tar.gz', 'nginx.bak.20151206-2153.tar.gz', 'nginx.bak.20151206-2226.tar.gz', 'php-fpm.conf', 'supervisord.conf', 'nginx.bak.20151206-2206.tar.gz', 'nginx.bak.20151206-2255.tar.gz', 'php-fpm.conf.default', 'varnish']