Author Topic: Startapp and Shell commands  (Read 5279 times)

0 Members and 1 Guest are viewing this topic.

terrycadd

  • Guest
Startapp and Shell commands
« on: November 29, 2007, 12:54:12 AM »
I've been using a method for a few years now called SHELL4 for starting a DOS application and waiting for it to finish, and then continuing with an AutoLISP function. It requires that you modify your Acad.pgp file and insert the following line below the SHELL command.
SHELL4,    ,               4,*OS Command: ,

I hate asking people to modify their Acad.pgp file for these AutoLISP programs to run, and I really don't want to ask them to load DOS-LIB into their library. Is there a method now included with AutoCAD that does the same thing that I may have overlooked?

Note: The first function, OpenNotepad-1, only works if you include the SHELL4 line in your Acad.pgp file. The second function, OpenNotepad-2, looks like it should work but doesn't. I gave up on this concept a long while back. The startapp function doesn't pause to return a result back to AutoLISP.

Code: [Select]
(defun c:OpenNotepad-1 (/ FileName% Text$)
  (if (not (findfile "C:\\Temp\\Temp.txt"))
    (vl-mkdir "C:\\Temp")
  );if
  (setq FileName% (open "C:\\Temp\\Temp.txt" "w"))
  (write-line "Erase this line. Type your message then save and exit." FileName%)
  (close FileName%)
  (command "SHELL4" "Notepad C:\\Temp\\Temp.txt")
  (setq FileName% (open "C:\\Temp\\Temp.txt" "r"))
  (setq Text$ (read-line FileName%))
  (close FileName%)
  (alert (strcat "You typed the message:\n" Text$))
  (princ)
);defun c:OpenNotepad-1

Code: [Select]
(defun c:OpenNotepad-2 (/ FileName% Text$)
  (if (not (findfile "C:\\Temp\\Temp.txt"))
    (vl-mkdir "C:\\Temp")
  );if
  (setq FileName% (open "C:\\Temp\\Temp.txt" "w"))
  (write-line "Erase this line. Type your message then save and exit." FileName%)
  (close FileName%)
  (startapp "Notepad C:\\Temp\\Temp.txt")
  (setq FileName% (open "C:\\Temp\\Temp.txt" "r"))
  (setq Text$ (read-line FileName%))
  (close FileName%)
  (alert (strcat "You typed the message:\n" Text$))
  (princ)
);defun c:OpenNotepad-2
« Last Edit: November 29, 2007, 01:16:46 AM by Terry Cadd »

kpblc

  • Bull Frog
  • Posts: 396
Re: Startapp and Shell commands
« Reply #1 on: November 29, 2007, 01:56:39 AM »
Another variant (whiout editing acad.pgp). Source: http://www.caduser.ru/cgi-bin/f1/board.cgi?t=8521ax by leha
Code: [Select]
(defun run_and_wait (strCommand / WScript_obj)
;    strCommand — command string with arguments
;       : "notepad.exe \"c:\\My Folder\\tmp.txt\""
;  Returns 0 | <%catch-all-apply-error%> | nil.
  (vl-load-com)
  (if (setq WScript_obj (vlax-get-or-create-object "WScript.Shell"))
    (vl-catch-all-apply 'vlax-invoke-method (list WScript_obj "Run" strCommand 4 :vlax-true))
  );if
);defun
Sorry for my English.

terrycadd

  • Guest
Re: Startapp and Shell commands
« Reply #2 on: November 29, 2007, 02:58:52 PM »
Thank you very much for the information on this function. It works great!
Terry

ttechnik

  • Newt
  • Posts: 24
Re: Startapp and Shell commands
« Reply #3 on: March 17, 2016, 03:50:42 PM »
Great idea!
Tamás Csepcsényi