到今天为止,我从事测绘工作已经满30年了,老话说“三十年河东,三十年河西“,我的三十年河东生涯就算是结束了,感谢各位明经通道的朋友们这十多年对我的支持和帮助,有空我会把这这些年来CAD二次开发的文档整理出来与大家共享。今天先来个LISP调用DOS命令行窗口执行DOS命令把运行结果写入文本文件的方法,这个方法的应用场景是可以在CAD里执行DOS命令行命令,例如获取计算机CPU内核个数、网络连接状态等,我用这个是为了基于CAD调用第三方软件的脚本执行多进程运算。- (defun get_ThisComputerTXT (CMDSTR)
- ;;;调用DOS命令获取计算机的参数,输出到C:\TEMP\ThisComputer.txt
- ;;;(get_ThisComputerTXT CMDSTR)
- ;;;CMDSTR 参数选择: IPCONFIG PING NumberOfCores NumberOfLogicalProcessors
- ;;;示例 (setq CMDSTR_LIST(get_ThisComputerTXT "PING 192.168.20.253"))
- ;;;示例 (setq CMDSTR_LIST(get_ThisComputerTXT "NumberOfCores"))
- ;;;示例 (setq CMDSTR_LIST(get_ThisComputerTXT "Powershell Get-PhysicalDisk"))
- (if (= (dos_dirp "C:\\TEMP") nil)
- (dos_mkdir "C:\\TEMP\\"))
- (if (findfile "C:\\TEMP\\ThisComputer.txt")
- (dos_delete "C:\\TEMP\\ThisComputer.txt"))
- (setq CMDSTR_LIST nil)
- (setq TMPBATFILE "C:\\TEMP\\ThisComputer_TMP.bat")
- (setq TMPBAT (open TMPBATFILE "w"))
- (cond
- ((or (= CMDSTR "NumberOfCores") (= CMDSTR "NumberOfLogicalProcessors"))
- (progn
- (write-line "wmic cpu get NumberOfCores > c:\\temp\\Thistemp.txt" TMPBAT)
- (write-line "wmic cpu get NumberOfLogicalProcessors >> c:\\temp\\Thistemp.txt"
- TMPBAT)
- (write-line "type c:\\temp\\Thistemp.txt > c:\\temp\\ThisComputer.txt" TMPBAT)))
- (t (write-line (strcat CMDSTR " > C:\\TEMP\\ThisComputer.txt") TMPBAT)))
- (close TMPBAT)
- (dos_exewait "C:\\TEMP\\ThisComputer_TMP.bat")
- (if (findfile "C:\\TEMP\\ThisComputer_TMP.bat")
- (dos_delete "C:\\TEMP\\ThisComputer_TMP.bat"))
- (if (findfile "C:\\TEMP\\Thistemp.txt")
- (dos_delete "C:\\TEMP\\Thistemp.txt"))
- )
|