gawel / chut Goto Github PK
View Code? Open in Web Editor NEWSmall tool to interact with shell pipes
Home Page: https://chut.readthedocs.org/en/latest/
Small tool to interact with shell pipes
Home Page: https://chut.readthedocs.org/en/latest/
Hi,
is it possible to implement this feature :
srv = ssh('root@...')
print(srv.sudo('-u', 'postgres').whoami())
If it's possible, this will be very nice API.
Best regards,
Stephane
currently with chut, we can't pass args with spaces unless shell=True
is passed
to the command:
>>> python("""-c 'print "a b"'""") >1
ERROR:chut:File "<string>", line 1
'print
^
SyntaxError: EOL while scanning string literal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/glehmann/Library/Python/2.7/lib/python/site-packages/chut/__init__.py", line 466, in __gt__
return self._write(filename, 'wb+')
File "/Users/glehmann/Library/Python/2.7/lib/python/site-packages/chut/__init__.py", line 523, in _write
self._raise(output=output)
File "/Users/glehmann/Library/Python/2.7/lib/python/site-packages/chut/__init__.py", line 547, in _raise
raise OSError(self.commands_line, output.stderr)
OSError: [Errno python -c 'print "a b"'] File "<string>", line 1
'print
^
SyntaxError: EOL while scanning string literal
passing several arguments helps - there are no exception, but the output is not
the expected one
>>> python("-c", 'print "a b"') >1
''
even with shell=True
, the output is not the as expected - the number of spaces
is not preserved:
>>> python("""-c 'print "a b"'""", shell=True) >1
a b
''
Several propositions comes to mind. In all the cases, don't split anything when
shell=True
- let the shell do all the splitting job - and passing several args
is not allowed when shell=True
. Then
shell=True
becomes the default. Don't split anything when shell=False andexecve
. Seems to be the most usual IMO.shell=False
is used with severalshell=False
and just pass the list as is to execve
.shell=False
stays the default. Args are split with shlex
to preserve the contentshell=None
to really do nothing on the args. Thereshell=False
stays the default. Args are split with shlex
to preserve the contentexecve
. Some examples:echo(["a b", "c"], "d e") # echo "a b" "c" "d" "e"
echo("a b c d e") # echo "a" "b" "c" "d" "e"
echo("'a b' c d e") # echo "a b" "c" "d" "e"
echo("'a b' c d e", sh=true) # echo "a b" "c" "d" "e"
echo("a b", "c", "d e", sh=True) # raise exception, too much args
my preference clearly goes to 1. Option 4 might be ok, but clearly introduce a complex
behavior that may not be desirable.
And of course there might be better options, perhaps even already there!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.