I'm using sh.py to run commands in docker containers:
>>> container = sh.docker.bake(CONTAINER_NAME).bash.bake('-c')
# example usage -- works correctly
# executes the bash equivalent of "/usr/bin/docker exec mycontainer bash -c 'ls -l foo bar baz'"
>>> container("ls -l foo bar baz")
# this does the same, but leaves me an object I can use for introspection and logging
>>> baked = container.bake("ls -l foo bar baz")
>>> baked() # executes correctly
# example stringification of the baked command
str(baked)
"/usr/bin/docker exec mycontainer bash -c ls -l foo bar baz"
# ..so
"/usr/bin/docker exec mycontainer bash -c 'ls -l foo bar baz'" # execution
"/usr/bin/docker exec mycontainer bash -c ls -l foo bar baz" # stringification
Is it reasonably possible to change this to be more accurate, for the purposes of logging what commands are being used?
Thanks for your development of this library, btw, it's probably my favorite subprocess tool -- and thanks for your time looking at this issue.
As a side note, since bash requires the actual command given to '-c' to follow as a single argument, I can't use sh.py as though it had access to the docker container directly. This is, overall, acceptable, though, because I can still use sh.py for the job of making things easier to reference. I'm not sure if this is a library limitation or my limited understanding of sh.py. Care to enlighten me?
# side note example
# Possible
container = sh.docker.bake(CONTAINER_NAME).bash.bake('-c')
container("ls -l foo bar baz")
# Not Possible, unless there's a way I don't know
# example 1
container.ls('-l', 'foo', 'bar', 'baz')
# example 2
container_ll = container.ls.bake('-l')
container_ll('foo', 'bar', 'baz')
Again, that last code snippet is just an aside.
I'm using sh.py to run commands in docker containers:
Is it reasonably possible to change this to be more accurate, for the purposes of logging what commands are being used?
Thanks for your development of this library, btw, it's probably my favorite subprocess tool -- and thanks for your time looking at this issue.
As a side note, since bash requires the actual command given to '-c' to follow as a single argument, I can't use sh.py as though it had access to the docker container directly. This is, overall, acceptable, though, because I can still use
sh.pyfor the job of making things easier to reference. I'm not sure if this is a library limitation or my limited understanding ofsh.py. Care to enlighten me?Again, that last code snippet is just an aside.