piccaso Posted May 16, 2004 Share Posted May 16, 2004 (edited) Hi! I wrote a litte function that enables to use php in autoit scripts. func php_eval($code) FileInstall("php.exe",@ScriptDir&"\php.exe",0) FileInstall("php.ini",@ScriptDir&"\php.ini",0) FileInstall("php4ts.dll",@ScriptDir&"\php4ts.dll",0) if FileExists(@scriptdir&"\temp") == 0 Then RunWait(@ComSpec & " /c " & 'mkdir ' & filegetshortname(@scriptdir&"\temp"), "", @SW_HIDE) do $temp_in = filegetshortname(@scriptdir&"\temp\"&Int(Random(10000000,99999999))&".php") until FileExists($temp_in) == 0 do $temp_out = filegetshortname(@scriptdir&"\temp\"&Int(Random(10000000,99999999))&".txt") until FileExists($temp_in) == 0 $fh = FileOpen($temp_in,2) fileWrite($fh,$code) FileClose($fh) RunWait(@ComSpec & " /c " & filegetshortname(@scriptdir&"\php.exe") & " -c " & filegetshortname(@scriptdir&"\php.ini") & " -f " & $temp_in & " >" & $temp_out, "", @SW_HIDE) $rval = fileread($temp_out,filegetsize($temp_out)) fileDelete($temp_in) fileDelete($temp_out) return $rval endfunc msgbox(0,"phpWrap",php_eval("<? echo phpversion(); ?>")) msgbox(0,"phpWrap",php_eval("<? i Am a parse error; ?>")) i thought i'll put it up here to inspire you the 2 last lines are just examples and please tell me, does this fileread($temp_out,filegetsize($temp_out)) realy read out the whole file contents? it seems to work but i'm not sure about it. of course you need php.exe,php.ini and php4ts.dll in your @ScriptDir when running/compiling the script but (as you can probably see) the exe will run without you have to make some changes in your php.ini i would al leas recommend 'html_errors=off' i'll put the whole package up somewhere if anybody cares (just let me know) Edited May 16, 2004 by piccaso CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
Gene Posted May 17, 2004 Share Posted May 17, 2004 Hi! and please tell me, does this fileread($temp_out,filegetsize($temp_out)) realy read out the whole file contents? it seems to work but i'm not sure about it.What makes you uncertain about it? Gene [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right... Link to comment Share on other sites More sharing options...
piccaso Posted May 17, 2004 Author Share Posted May 17, 2004 The Helpfile Example looks Different ; Read in 1 character at a time until the EOF is reached While 1 $chars = FileRead($file, 1) If @error = -1 Then ExitLoop MsgBox(0, "Char read:", $chars) Wend And i'm not sure that one 'char' is one 'byte' ... CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
ezzetabi Posted May 18, 2004 Share Posted May 18, 2004 One char is one byte indeed. Link to comment Share on other sites More sharing options...
Valik Posted May 18, 2004 Share Posted May 18, 2004 Except if a char is multi-byte as is possible with some languages (One being Japanese, I think). Link to comment Share on other sites More sharing options...
Gene Posted May 18, 2004 Share Posted May 18, 2004 (edited) The Helpfile Example looks Different ; Read in 1 character at a time until the EOF is reached While 1 $chars = FileRead($file, 1) If @error = -1 Then ExitLoop MsgBox(0, "Char read:", $chars) Wend And i'm not sure that one 'char' is one 'byte' ...This is an example. In fact you can use this command/function to read any portion other than 0% into a variable. If you use the FileSize() command/function to specify the number of bytes/characters to be read in, it reads 100% of the bytes/characters into the variable. It seems to me that the FileRead() command/function is useful in 4 scenarios: 1- to read the the "header" of a file (to determine field and record lengths) 2- when the fields and records in a file are of fixed length(s) and there are no delimiters 3- when the length of a record is specified in the header of the record and there are no delimiters 4- to grab the entire file using the FileSize command/function Gene PS. Having gone out on that limb, I will be disappointed if 2 or 3 additional uses aren't pointed out by others. Edited May 18, 2004 by Gene [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now