0Day Forums
How do I open a file for edit from the command line under Windows? - Printable Version

+- 0Day Forums (https://zeroday.vip)
+-- Forum: Coding (https://zeroday.vip/Forum-Coding)
+--- Forum: .bat & .wsf & .cmd (https://zeroday.vip/Forum-bat-wsf-cmd)
+--- Thread: How do I open a file for edit from the command line under Windows? (/Thread-How-do-I-open-a-file-for-edit-from-the-command-line-under-Windows)



How do I open a file for edit from the command line under Windows? - corieocngfdqtcw - 07-23-2023

How do I open a file for `edit` from the command line under Windows?

Mainly I am looking to open the file in the default editor associated for it (not to be confused with default action for this filetype).

This is different than just "executing" the file, so `start filename` is not a solution.

Note: this would require to use ShellExecute in one way or another.

Update: I added `Python` as an alternative to `batch`.


RE: How do I open a file for edit from the command line under Windows? - Proextracolumella940 - 07-23-2023

Here is a sample Python script that opens a file for edit, if there is an editor assigned to its filetype.

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



RE: How do I open a file for edit from the command line under Windows? - clodaghgtawebxgs - 07-23-2023

64 bit Windows does not support edit command.

[To see links please register here]


To open file in with default associated app, in CMD use `start <<file_path>>`
Reference:

[To see links please register here]


To open a file in notepad, in CMD use `notepad <<file_path>>` in CMD
- if file is not associated with default app to open - error will be displayed