找回密码
 加入
搜索
查看: 2222|回复: 8

如何将一个字符串编程命令

[复制链接]
发表于 2009-7-19 15:20:06 | 显示全部楼层 |阅读模式
比如我从记事本中读取了一个文本“run("xxxx.exe")”
我想让程序把这个文本转化成一条可执行的命令,eval无法实现。
读取文本进行判断用个switch语句这样做我觉得有点太麻烦,有没有简单一点的方法呢?
发表于 2009-7-19 16:14:19 | 显示全部楼层
Execute(FileReadLine("a.txt", 1))

评分

参与人数 1金钱 +8 收起 理由
lynfr8 + 8 新东西,学习了!

查看全部评分

 楼主| 发表于 2009-7-19 17:00:22 | 显示全部楼层
这个貌似不行
我用的这个方法..
Func zhixing($v,$q)
        ;MsgBox(0,"0",$q)
        Local $a="",$b="",$c="",$d="",$e="",$f="",$g="",$h="",$i="",$j="",$k=""
$text = StringReplace($q, ",", ",")
$numreplacements = @extended
Switch $numreplacements
        Case 0
                $a=$q
        Case 1
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1)
        Case 2
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1)
        Case 3
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1,StringInStr($q,",",0,3)-StringInStr($q,",",0,2)-1)
                $d=StringMid($q,StringInStr($q,",",0,3)+1)
        Case 4
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1,StringInStr($q,",",0,3)-StringInStr($q,",",0,2)-1)
                $d=StringMid($q,StringInStr($q,",",0,3)+1,StringInStr($q,",",0,4)-StringInStr($q,",",0,3)-1)
                $e=StringMid($q,StringInStr($q,",",0,4)+1)
        Case 5
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1,StringInStr($q,",",0,3)-StringInStr($q,",",0,2)-1)
                $d=StringMid($q,StringInStr($q,",",0,3)+1,StringInStr($q,",",0,4)-StringInStr($q,",",0,3)-1)
                $e=StringMid($q,StringInStr($q,",",0,4)+1,StringInStr($q,",",0,5)-StringInStr($q,",",0,4)-1)
                $f=StringMid($q,StringInStr($q,",",0,5)+1)
        Case 6
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1,StringInStr($q,",",0,3)-StringInStr($q,",",0,2)-1)
                $d=StringMid($q,StringInStr($q,",",0,3)+1,StringInStr($q,",",0,4)-StringInStr($q,",",0,3)-1)
                $e=StringMid($q,StringInStr($q,",",0,4)+1,StringInStr($q,",",0,5)-StringInStr($q,",",0,4)-1)
                $f=StringMid($q,StringInStr($q,",",0,5)+1,StringInStr($q,",",0,6)-StringInStr($q,",",0,5)-1)
                $g=StringMid($q,StringInStr($q,",",0,6)+1)
        Case 7
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1,StringInStr($q,",",0,3)-StringInStr($q,",",0,2)-1)
                $d=StringMid($q,StringInStr($q,",",0,3)+1,StringInStr($q,",",0,4)-StringInStr($q,",",0,3)-1)
                $e=StringMid($q,StringInStr($q,",",0,4)+1,StringInStr($q,",",0,5)-StringInStr($q,",",0,4)-1)
                $f=StringMid($q,StringInStr($q,",",0,5)+1,StringInStr($q,",",0,6)-StringInStr($q,",",0,5)-1)
                $g=StringMid($q,StringInStr($q,",",0,6)+1,StringInStr($q,",",0,7)-StringInStr($q,",",0,6)-1)
                $h=StringMid($q,StringInStr($q,",",0,7)+1)
        Case 8
                $a=StringMid($q,1,StringInStr($q,",",0,1)-1)
                $b=StringMid($q,StringInStr($q,",",0,1)+1,StringInStr($q,",",0,2)-StringInStr($q,",",0,1)-1)
                $c=StringMid($q,StringInStr($q,",",0,2)+1,StringInStr($q,",",0,3)-StringInStr($q,",",0,2)-1)
                $d=StringMid($q,StringInStr($q,",",0,3)+1,StringInStr($q,",",0,4)-StringInStr($q,",",0,3)-1)
                $e=StringMid($q,StringInStr($q,",",0,4)+1,StringInStr($q,",",0,5)-StringInStr($q,",",0,4)-1)
                $f=StringMid($q,StringInStr($q,",",0,5)+1,StringInStr($q,",",0,6)-StringInStr($q,",",0,5)-1)
                $g=StringMid($q,StringInStr($q,",",0,6)+1,StringInStr($q,",",0,7)-StringInStr($q,",",0,6)-1)
                $h=StringMid($q,StringInStr($q,",",0,7)+1,StringInStr($q,",",0,8)-StringInStr($q,",",0,7)-1)
                $i=StringMid($q,StringInStr($q,",",0,8)+1)
EndSwitch
;MsgBox(0,"1",$a&" "&$b&" "&$c&" "&$d)


        Switch $v
                Case "RUN"
                        RUN ($a,$b,$c,$d)
                Case "ControlClick"
                        ControlClick($a,$b,$c,$d)
                Case "ControlDisable"
                        ControlDisable($a,$b,$c)
                Case "ControlEnable"
                        ControlEnable($a,$b,$c)
                Case "ControlFocus"
                        ControlFocus($a,$b,$c)
                Case "ControlHide"
                        ControlHide($a,$b,$c)
                Case "ControlListView"
                        ControlListView($a,$b,$c,$d,$e,$f)
                Case "ControlMove"
                        ControlMove($a,$b,$c,$d,$e,$f,$g)
                Case "ControlSend"
                        ControlSend($a,$b,$c,$d,$e)
                Case "ControlSetText"
                        ControlSetText($a,$b,$c,$d,$e)
                Case "ControlShow"
                        ControlShow($a,$b,$c)
                Case "ControlTreeView"
                        ControlTreeView($a,$b,$c,$d,$e,$f)
                Case "WinActivate"
                        WinActivate($a,$b)
                Case "WinClose"
                        WinClose($a,$b)
                Case "WinFlash"
                        WinFlash($a,$b,$c,$d)
                Case "WinKill"
                        WinKill($a,$b)
                Case "WinMenuSelectItem"
                        WinMenuSelectItem($a,$b,$c,$d,$e,$f,$g,$h,$i)
                Case "WinMinimizeAll"
                        WinMinimizeAll()
                Case "WinMinimizeAllUndo"
                        WinMinimizeAllUndo()
                Case "WinMove"
                        WinMove($a,$b,$c,$d,$e,$f,$g)
                Case "WinSetOnTop"
                        WinSetOnTop($a,$b,$c)
                Case "WinSetState"
                        WinSetState($a,$b,$c)
                Case "WinSetTitle"
                        WinSetTitle($a,$b,$c)
                Case "WinSetTrans"
                        WinSetTrans($a,$b,$c)
                Case "WinWait"
                        WinWait($a,$b,$c)
                Case "WinWaitActive"
                        WinWaitActive($a,$b,$c)
                Case "WinWaitClose"
                        WinWaitClose($a,$b,$c)
                Case "WinWaitNotActive"
                        WinWaitNotActive($a,$b,$c)
                Case "Send"
                        Send($a,$b)
                Case "SendKeepActive"
                        SendKeepActive($a,$b)
                Case "Sleep"
                        Sleep($a)
        EndSwitch
        EndFunc
无奈,正则表达式不过关=。=!
发表于 2009-7-19 17:38:04 | 显示全部楼层
2楼的代码绝对可以
楼主将简单的事情搞得复杂了
 Execute(FileReadLine("a.txt", 1))
Sleep(3000)
Execute(FileReadLine("a.txt", 2))
a.txt两行内容:
 Run("Notepad.exe", "", @SW_MAXIMIZE)
ShellExecute("Notepad.exe")

评分

参与人数 1金钱 +5 贡献 +5 收起 理由
顽固不化 + 5 + 5 又学了一招

查看全部评分

发表于 2009-7-19 18:16:44 | 显示全部楼层
是啊,二楼的代码很简单很实用~
发表于 2009-7-19 19:13:31 | 显示全部楼层
http://www.autoitx.com/forum.php ... &extra=page%3D1
CreateProcess,代替ShellExecute和ShellExecuteWait
这个UDF楼主也可借鉴下
 楼主| 发表于 2009-7-19 19:49:02 | 显示全部楼层
THANKS ALL
发表于 2009-7-19 20:29:38 | 显示全部楼层
可能需要装了AU3时才能起作用
发表于 2009-12-6 17:35:12 | 显示全部楼层
非常好呀,借鉴
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 14:41 , Processed in 0.120112 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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