usr
usr

Reputation: 705

Python - opening cli/gui editors (vim, nano, geany...)

I'd like to open an editor (cli or gui-based) via Python script. I can do this with os.system('vim file'), but I'd also like to get output in case command fails. subprocess.getstatusoutput('vim file') doesn't work for opening programs with specific interface.

What's the best alternative?

Upvotes: 0

Views: 843

Answers (2)

Fred Foo
Fred Foo

Reputation: 363707

subprocess.check_call([EDITOR, file_path])

will raise an OSError exception if EDITOR fails to run.

Upvotes: 2

0xd
0xd

Reputation: 1901

You can use os.execv(path, args) if the command fails, an OSError will be thrown. You can find more details on os.execv documentation.

Upvotes: 0

Related Questions