如何将一个字符串编程命令
比如我从记事本中读取了一个文本“run("xxxx.exe")”我想让程序把这个文本转化成一条可执行的命令,eval无法实现。
读取文本进行判断用个switch语句这样做我觉得有点太麻烦,有没有简单一点的方法呢? Execute(FileReadLine("a.txt", 1)) 这个貌似不行
我用的这个方法..
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
无奈,正则表达式不过关=。=! 2楼的代码绝对可以
楼主将简单的事情搞得复杂了 Execute(FileReadLine("a.txt", 1))
Sleep(3000)
Execute(FileReadLine("a.txt", 2))
a.txt两行内容: Run("Notepad.exe", "", @SW_MAXIMIZE)
ShellExecute("Notepad.exe")
是啊,二楼的代码很简单很实用~ http://www.autoitx.com/forum.php?mod=viewthread&tid=5047&extra=page%3D1
CreateProcess,代替ShellExecute和ShellExecuteWait
这个UDF楼主也可借鉴下 THANKS ALL 可能需要装了AU3时才能起作用 非常好呀,借鉴
页:
[1]