plumbum icon indicating copy to clipboard operation
plumbum copied to clipboard

run() takes from 1 to 2 positional arguments but 3 were given

Open jonschull opened this issue 6 years ago • 1 comments

I'm trying to capture error messages from the process I'm running and (not for the first time), I can't figure out the right way pass a command line switch and a parameter.

>>> command
LocalCommand(/bin/ls)

>>> print(command.run('-l', '*'))

Traceback (most recent call last):
  File "<pyshell>", line 1, in <module>
TypeError: run() takes from 1 to 2 positional arguments but 3 were given

(I assume self is the invisible positional argument, but my question remains.]

Thanks again

jonschull avatar Apr 11 '18 01:04 jonschull

Just pretend a Command is a function.

from plumbum.cmd import ls
print(ls('-l', '*'))

Though, * will not be expanded so that will probably give you an error unless you have a file named *. You can expand * yourself:

from plumbum import local
filelist = local.cwd // '*'
print(ls('-l', filelist))

// expands globs.

henryiii avatar Apr 11 '18 05:04 henryiii