找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 664|回复: 0

[每日一码] (XDRX API)AutoLisp SHELL 扩展

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2017-12-16 17:37:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×


XDRX API 从 2017.1215版本,提供SHELL扩展给LISP,例子如下,关于SHELL可以做什么,可以百度。

SHELL函数:
xdrx_shell_open
xdrx_shell_readdata
xdrx_shell_writedata
xdrx_shell_close
xdrx_shell_getlasterror


  1. ;;; Test 2
  2. ;;; 改变目录到 D盘的drivers目录, 获取目录
  3. ;;; 列表并打印到AUTOCAD命令行
  4. ;;; 如何使用 && 和命令的组合的例子。
  5. (defun c:test2 (/ handle sResult)
  6.   (setq        handle (xdrx_shell_open "c:\\windows\\system32\\cmd.exe"
  7.                           "/c d: && cd \\drivers\\ && dir"
  8.                )
  9.   )
  10.   (if (/= nil handle)
  11.     (progn
  12.       (while (/= nil (setq sResult (xdrx_shell_readdata handle)))
  13.         (princ sResult)
  14.       )
  15.       (xdrx_shell_close handle)
  16.     )
  17.   )
  18.   (princ)
  19. )



搜狗截图20171216172612.gif


  1. ;;; test 3
  2. ;;; 改变目录到 D盘的drivers目录, 获取目录
  3. ;;; 列表并打印到AUTOCAD命令行
  4. ;;; 如何使用管道和 && 和命令的组合的例子。
  5. (defun c:test3 (/ handle sResult)
  6.   (setq        handle (xdrx_shell_open "c:\\windows\\system32\\cmd.exe"
  7.                           "/c d: && cd \\drivers\\ && dir | sort"
  8.                )
  9.   )
  10.   (if (/= nil handle)
  11.     (progn
  12.       (while (/= nil (setq sResult (xdrx_shell_readdata handle)))
  13.         (princ sResult)
  14.       )
  15.       (xdrx_shell_close handle)
  16.     )
  17.   )
  18.   (princ)
  19. )



搜狗截图20171216174056.gif

  1. (defun c:test4 (/ handle sResult sContents)
  2.   (setq        handle (xdrx_shell_open "c:\\windows\\system32\\cmd.exe"
  3.                           "/c type \\Windows\\system.ini"
  4.                )
  5.   )
  6.   (if (/= nil handle)
  7.     (progn
  8.       (setq sContents "")
  9.       (while (/= nil (setq sResult (xdrx_shell_readdata handle)))
  10.         (setq sContents (strcat sContents sResult))
  11.       )
  12.       (xdrx_shell_close handle)
  13.     )
  14.   )
  15.   (princ sContents)
  16.   (princ)
  17. )


搜狗截图20171216173205.gif

  1. ;;; Opens cmd.exe shell using the envirnment variable %comspec% if set.
  2. ;;; The sort program is run and input is provided via the xdrx_shell_writedata
  3. ;;; function. This test provides a single string with carriage seperating
  4. ;;; the words of the input. This is one way to provide line buffered input.

  5. (defun c:Test5 (/ handle sResult)
  6.   (setq handle (xdrx_shell_open "%comspec%" "/c sort"))
  7.   (if (/= nil handle)
  8.     (progn
  9.       (xdrx_shell_writedata handle "There\nis\na\nfly\n")
  10.       (setq sResult (xdrx_shell_readdata handle))
  11.       (if (/= nil sResult)
  12.         (princ sResult)
  13.       )
  14.     )
  15.     (xdrx_shell_close handle)
  16.   )
  17.   (princ)
  18. )





  1. ;;; Opens cmd.exe shell using the envirnment variable %comspec% if set.
  2. ;;; The sort program is run and input is provided to it through xdrx_shell_writedata
  3. ;;; by calling it multiple times.
  4. (defun c:Test6 (/ aList handl sResult)
  5.   (setq aList (list "Lost" "in" "the" "swamp" "with" "the" "gaters"))
  6.   (setq handle (xdrx_shell_open "%comspec%" "/c sort"))
  7.   (if (/= nil handle)
  8.     (progn
  9.       (foreach s aList (xdrx_shell_writedata handle (strcat s "\n")))
  10.       (setq sResult (xdrx_shell_readdata handle))
  11.       (if (/= nil sResult)
  12.         (princ sResult)
  13.       )
  14.     )
  15.     (xdrx_shell_close handle)
  16.   )
  17.   (princ)
  18. )




论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-27 00:36 , Processed in 0.454267 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表