2

I took a function for python that I have found online

def sh_escape(s):
return s.replace("(","\\(").replace(")","\\)").replace(" ","\\ ")

And I used it with os.system (). It looks like this:

os.system(sh_escape('curl -X PUT http://admin:admin@127.0.0.1:5984/test/')+file+sh_escape(' -d @/home/user/Downloads/') +file)

file is the name he reads with os.walk()

When I run it, I am becoming

sh: 1: curl -X PUT http://admin:admin@127.0.0.1:5984/test/file -d @/home/user/Downloads/file: not found

Do you know, where my mistake is ? if I run the command directly in the terminal it works.

Python 3 used

  • It is expecting a she-bang. Try subprocess without the shell: https://stackoverflow.com/questions/4813238/difference-between-subprocess-popen-and-os-system – Stephen Rauch Jun 19 '18 at 01:24
  • 1
    Your `sh_escape` function escapes all the spaces, including the ones between the command and its arguments, and between all of the arguments. So you're not asking it to look for a command named `curl` on your PATH and run it with arguments `-X`, `PUT`, etc., but to find a command named `curl -X PUT …` on your PATH. And of course there is no such command. – abarnert Jun 19 '18 at 01:37
  • 1
    More generally, why are you trying to reinvent multiple wheels here? Just use the `subprocess` module, and pass in a list of arguments. – abarnert Jun 19 '18 at 01:38
  • thanks guys, the solution was with subprocess – Tricker Macedonia Jun 19 '18 at 10:32

1 Answers1

2

Did you install curl? Mac os: brew install curl Linux: yum install curl or apt-get install curl

amb1s1
  • 1,995
  • 5
  • 22
  • 26