0

I want to add a wrapper around a specific shell command. This will run in Linux only and I don't care about cross platform support. This code works, but is there a better way to achieve this? Or am I opening myself up to any weird behavior?

import os
import sys

# Do my personal validation here
do_some_validation(sys.argv) 

# Now call the real program
os.execv('/usr/bin/some-command', sys.argv)

Thanks!

user3827132
  • 129
  • 1
  • 2
  • 9

1 Answers1

3

You may use subprocess

import subprocess
subprocess.call(['/usr/bin/some-command', arg1, arg2])

subprocess is better than os in a way, in that it has more control over execution of a command, whereas os just throws it to bash.

pyrrhic
  • 1,769
  • 2
  • 15
  • 27
Alexey Smirnov
  • 2,573
  • 14
  • 20
  • What does subprocess offer me specifically? When I was googling before posting this I saw a variation of your comment all over, but in this case I want to replace the executable with the one I am wrapping. I have no need to get the return code, out/err, do error handling, etc, etc. – user3827132 Mar 29 '16 at 19:31
  • In your case you can stay with os, of course. No need to switch to subprocess at all, but in future if you are going to expand your script you may need some return codes,pipes, etc, oum ya need it. – Alexey Smirnov Mar 30 '16 at 09:22