Azrael Posted August 13, 2009 Share Posted August 13, 2009 Hi there, I've been looking at using TCP comms for a new tool I'm writing (it's my learning curve type thing, write odd tools to help me learn). I've managed to write a TCP Server that sits and listens for connections quite happily. I can connect to it via Telnet (Under WinXP) and type at the keyboard, it echoes back what I type on the server console. So I thought I'd try to make the server do something useful, so I changed the behaviour of handling data sent to it so that if the data is 'A:<some command>' it takes that as an AutoIT command to execute directly - anything else and it simply puts it out on the screen. When it gets the A: command, it removes the 'A:' from it, displays the command to be executed (in this case, Beep(500, 500)). But instead of executing the command, it says it can't parse the command... however it's obviously tried to execute the command as the error message is from AutoIT itself. To execute the AutoIT commands I'm using the AutoItExecute function which can be found below. Func AutoItExecute($Cmd) $cmd = binarytostring($cmd, 1) RunWait(@AutoItExe & ' /AutoIt3ExecuteLine "' & $Cmd & '"') EndFunc I'm using it literally as displayed, even if I comment out the 'BinaryToSTring' line - it still complains. Am I doing something really silly by trying to get AutoIT to execute it's own internal commands? Is there another way I could accomplish this? Any help, suggestions or anything would be greatly appreciated >_< Az Link to comment Share on other sites More sharing options...
colafrysen Posted August 13, 2009 Share Posted August 13, 2009 Execute() [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size] Link to comment Share on other sites More sharing options...
Azrael Posted August 14, 2009 Author Share Posted August 14, 2009 Execute()Not that I'm doubting what you say but in the helpfile - execute() doesn't actually say it can execute internal autoit commands - it simply says it evaluates an expression - which is probably where I'm confused.In any case, I will give it a go - thanks >_<Az Link to comment Share on other sites More sharing options...
jvanegmond Posted August 14, 2009 Share Posted August 14, 2009 Yes, Execute "runs" a line of AutoIt code including all native AutoIt methods. I think you can even call Execute inside Execute. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Scriptonize Posted August 14, 2009 Share Posted August 14, 2009 Yes, Execute "runs" a line of AutoIt code including all native AutoIt methods. I think you can even call Execute inside Execute. Doesn't the au3 commands need to be inside an au3 file? When I try to use them from the command line: Autoit3.exe Execute("Beep(100,100)") then it pops up with error: Line 0 (File "C:\program files\AutoIT3.3.0.0\Execute(Beep(100,100))"): Error: Error opening the file When I however place the beep statement into an au3 file (myBeep.au3) and run it from the command line with: Autoit3.exe mybeep.au3 It works just fine. Can you give an example how your solution should be used? If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
Azrael Posted August 14, 2009 Author Share Posted August 14, 2009 Yes, Execute "runs" a line of AutoIt code including all native AutoIt methods. I think you can even call Execute inside Execute.Now that's pretty cool - I did see Execute() in the help file but it didn't (initially) sound like what I wanted.Okay, after some messing around with my TCP server, it now works wonderfully - BEEP doesn't work (as in, no sound is ever heard) but that's minor, msgbox, cdtray and a few other commands work.The problem I was having wasn't to do with the user function _AutoITExecute - but it was because the data received had a ton of whitespace at the end, which I hadn't wiped with StringStripWS.Thanks >_<Az Link to comment Share on other sites More sharing options...
Azrael Posted August 14, 2009 Author Share Posted August 14, 2009 It works just fine. Can you give an example how your solution should be used? I can happily do this >_< $z = Execute("<AutoITCommand-Here>") Replace 'AutoITCommand-Here' with what you'd like it to do. If your command is in a variable, then you also don't need the quotes. So something like the following should work just fine: Local $MyCmd, $z $MyCmd = "Beep(100, 100)" $z = Execute($MyCmd) HTH, Az Link to comment Share on other sites More sharing options...
Scriptonize Posted August 14, 2009 Share Posted August 14, 2009 OK, but then You use the Execute command within an au3 file. That would make sense. I thought for a split second, it was used from the command line (which I didn't got working). Thanx for the reply. If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
jvanegmond Posted August 14, 2009 Share Posted August 14, 2009 OK, but then You use the Execute command within an au3 file. That would make sense. I thought for a split second, it was used from the command line (which I didn't got working). Thanx for the reply. You can also run script from the command line, but you do not need Execute. C:\Program Files\AutoIt3>AutoIt3.exe /AutoIt3ExecuteLine "MsgBox(0,'','Hello World')" github.com/jvanegmond Link to comment Share on other sites More sharing options...
Yuraj Posted August 14, 2009 Share Posted August 14, 2009 Hi, you can look at my old test: server_client_commands.rar You can send commands/scripts encrypted from client to server >_< So there are only two base commands: 0x9D + encrypted code - for executing code , 0x22 - for terminating server. You can add more.. ShellExecute("http://www.yuraj.ucoz.com")ProcessClose(@AutoItPID) Link to comment Share on other sites More sharing options...
Nutster Posted August 14, 2009 Share Posted August 14, 2009 Now that's pretty cool - I did see Execute() in the help file but it didn't (initially) sound like what I wanted.Okay, after some messing around with my TCP server, it now works wonderfully - BEEP doesn't work (as in, no sound is ever heard) but that's minor, msgbox, cdtray and a few other commands work.The problem I was having wasn't to do with the user function _AutoITExecute - but it was because the data received had a ton of whitespace at the end, which I hadn't wiped with StringStripWS.Thanks >_<AzKeep in mind that any actions you do this way will occur on your server, not the client, if they are different machines. Now you ready to create a web server (Port 80). David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd... Link to comment Share on other sites More sharing options...
Scriptonize Posted August 14, 2009 Share Posted August 14, 2009 You can also run script from the command line, but you do not need Execute. C:\Program Files\AutoIt3>AutoIt3.exe /AutoIt3ExecuteLine "MsgBox(0,'','Hello World')" Ah Ha, that I didn't knew. Many thanx for your info. I tried your code and it works fine. If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
jvanegmond Posted August 14, 2009 Share Posted August 14, 2009 Keep in mind that any actions you do this way will occur on your server, not the client, if they are different machines. Now you ready to create a web server (Port 80). Or he can save himself some trouble and use this http://www.autoitscript.com/forum/index.php?showtopic=68851 Shameless self advertising for the win. >_< github.com/jvanegmond 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