How to open a file for editing from the command line under Windows?

How to open a file for editfrom the command line under Windows?

Basically I am looking to open a file in its standard editor (not to be confused with the default action for this type of file).

This differs from the "execution" of the file, therefore start filenameit is not a solution.

Note: this will require you to use ShellExecute anyway.

Update: I added Pythonas an alternative batch.

+5
source share
1 answer

Python script, , , .

import os
from ctypes import c_int, WINFUNCTYPE, windll
from ctypes.wintypes import HWND, LPCSTR, UINT
prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)

filename = "readme.txt"
os.startfile(filename, "edit")

try:
    os.startfile(filename, "edit")
except WindowsError, e:
    MessageBox(text=str(e))
+1

All Articles