mwilliamson / spur.py

Run commands and manipulate files locally or over SSH using the same interface
BSD 2-Clause "Simplified" License
267 stars 37 forks source link

Writing str command instead of list #53

Closed gokhanm closed 7 years ago

gokhanm commented 7 years ago

If i'll use spur module in my project. I want to write shell commands in str variable instead of the list. I think it's easy and fast way to do this.

import spur

shell = spur.LocalShell()
cmd = "echo -n hello"
result = shell.run(cmd)
print(result.output) # prints hello

Do you accept PR like below for local.py, shell.py etc. ?

encoding = kwargs.pop("encoding", None)
cwd = kwargs.get('cwd')
command = command.split() # Return a list of the words in the string
command_in_cwd = self._shell_type.generate_run_command(command, *args, store_pid=store_pid, **kwargs)
mwilliamson commented 7 years ago

I prefer the API to require a list to avoid issues with escaping and splitting. For instance, just splitting on whitespace might give unexpected behaviour if it contains quotes.

An alternative is to run the command through an actual shell, for instance:

cmd = "echo -n hello"
shell.run(["sh", "-c", cmd])
gokhanm commented 7 years ago

Yea you are right. it may cause a problem.