Manuel_Kunde Posted August 19, 2021 Posted August 19, 2021 Hi, I need a small lisp that opens and closes a file for me in the background. Nothing needs to be done. In this lisp the file is opened but not closed. (defun c:open_close_explorer () (setq Path "Y:\\Folder\\Data\\Test.txt") (setq File (StartAPP "Explorer.Exe" Path)) (close File) (princ) ) Does anyone have an idea? Quote
Lee Mac Posted August 19, 2021 Posted August 19, 2021 When executing the startapp function, the instance of explorer runs within a separate asynchronous process from the evaluation of the AutoLISP program, and, as such, you would need to use a function to interface with the set of running Windows processes, identify the instance of explorer (or more likely, Windows Notepad, though the program used to open the file would ultimately depend on the .txt file association configured on the user's PC), and terminate such process. However, the whole thing seems rather pointless. 1 Quote
Grrr Posted August 19, 2021 Posted August 19, 2021 Here are some topics with subfunctions that may be of interest: _WbemGet and _KillProcess . Quote
mhupp Posted August 20, 2021 Posted August 20, 2021 (edited) 15 hours ago, Manuel_Kunde said: "opens and closes a file for me in the background. Nothing needs to be done." Could you just use the read function of open? Don't really know why you would want to open a file and then immediately close it. (defun C:foo (/ F line txt) (setq F (open Y:\\Folder\\Data\\Test.txt "r")) ;opens file to read (while (setq line (read-line F)) (if (not (null line)) (setq txt (append txt (list line))) ;adds each line of txt file to list txt ) ;end if ) ;end while (close F) (foreach ln txt (prompt (strcat ln "\n")) ) (princ) ) Edited August 20, 2021 by mhupp 1 Quote
Manuel_Kunde Posted August 20, 2021 Author Posted August 20, 2021 2 hours ago, mhupp said: Could you just use the read function of open? Don't really know why you would want to open a file and then immediately close it. (defun C:foo (/ F line txt) (setq F (open Y:\\Folder\\Data\\Test.txt "r")) ;opens file to read (while (setq line (read-line F)) (if (not (null line)) (setq txt (append txt (list line))) ;adds each line of txt file to list txt ) ;end if ) ;end while (close F) (foreach ln txt (prompt (strcat ln "\n")) ) (princ) ) Exactly what i need, thanks. Quote
BIGAL Posted August 21, 2021 Posted August 21, 2021 (edited) Like lee why ? If you want a lets look use a lisp open a file and read each line then can release file name. (setq Path "yourfile") (setq fo (open path "R")) (while (setq str (read-line fo)) (princ str) (princ "\n") ) (close fo) Mhupp forgot to hit submit button yesterday same idea. Edited August 21, 2021 by BIGAL 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.