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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.