0

I am using pexpect.run to execute a command. See below:

cmd = "grep -L killed /dir/dumps/*MAC-66.log"
output = pexpect.run(cmd)

When I run this, output equals to:

grep: /dir/dumps/*MAC-66.log: No such file or directory

But when I run the same command in my shell, it works, everytime. I don't see the problem. Any help is appreciated! Does pexpect.run require the command to be split in some fancy way?

theAlse
  • 5,577
  • 11
  • 68
  • 110

1 Answers1

1

Your shell is interpreting the glob, pexpect is not. You could either use python's glob.glob() function to evaluate the glob yourself, or run it through your shell, for example:

cmd = "bash -c 'grep -L killed /dir/dumps/*MAC-66.log'"

Also, if all you're after is output of this command, you ought to check out the subprocess module.

FatalError
  • 52,695
  • 14
  • 99
  • 116