eshaan7 / Flask-Shell2HTTP

Execute shell commands via HTTP server (via flask's endpoints).
https://flask-shell2http.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
170 stars 28 forks source link

A way to get binary output #44

Closed pink-red closed 1 year ago

pink-red commented 1 year ago

First of all, thank you for this project! It was very easy to set up a couple of endpoints.

Now, I am trying to create another endpoint for a command which returns binary output and I'm getting an error:

"'utf-8' codec can't decode byte 0xff in position 0: invalid start byte"

Is there a way to configure an endpoint to return binary data, for example, in base64?

eshaan7 commented 1 year ago

Is there a way to configure an endpoint to return binary data, for example, in base64?

You could try the unix pipe | your command to base64. For example, echo "Hello" | base64. Might need to put your command in a custom script (.sh/.py/etc) to use pipes though (refer to this example).

You may be able to use a decorator to achieve this too (example).

pink-red commented 1 year ago

You could try the unix pipe | your command to base64.

Thank you for your suggestion. I ended up creating this wrapper script:

#!/bin/sh
<the-command> "$@" | base64 --wrap 0

and it's called like this:

shell2http.register_command(endpoint="some-enpoint", command_name="./script.sh")

Works like a charm!