Saved Bookmarks
| 1. |
Solve : Putty/VBS Help? |
|
Answer» I run a Team Fortress 2 server that uses Linux. To access it, I use Putty to run commands from my windows box, and Screen to actually run the server program. I'm trying to make a VBS file automatically run a specific command from inside the server program, and I'm having some weird errors. I'm using SendKeys and it's working for most of the script. It manages to write everything successfully, until it reaches Screen, where it only writes half of what I'm trying to run. Set WshShell = WScript.CreateObject("WScript.Shell")I've tried changing the time it waits after it's opened the server software through screen and before it starts typing, but it's still only managing to write "oad"; sometimes it writes "sm_reoad". The whole command it's supposed to write is "sm_reloadadmins", but it's not getting anywhere close to that. Edit: I've even tried to do each character individually, and it's not working.Try giving focus to the application before isssuing the first sendkeys operation: Code: [Select]WshShell.AppActivate("Window Title") WScript.Sleep 1000 Change the "Window Title" to the actual window title you're sending the keys to. Sendkeys needs to be performed like a well choreographed ballet. If the window you're sending keys to loses focus, all bets are off and you MAY end up sending keys to the wrong window. Try lowering the sleep times especially the one with a 20000 value. Good luck. I was experimenting with the 20 second wait, because I just assumed it NEEDED more time to wait before it would accept input. I started with a 1s wait. But Sidewinder, if the app is not active, how can it write anything at all?I can't duplicate the Putty window you're seeing (I only get PuTTY Configuration). Some suggestions:
Quote if the app is not active, how can it write anything at all? Sendkeys simply sends out keystrokes. Whether any application is there to catch them makes no difference. Any chance you can use command line parameters instead of the GUI? And here i thought you needed some windows re-glazed... Quote from: Sidewinder on July 09, 2012, 03:39:42 PM I can't duplicate the Putty window you're seeing (I only get PuTTY Configuration).1. Can't replace enter keys with TAB or it won't execute the text. I tried doing it, and it typed out all the commands fine...into the user input field. 2. Done, now it sends "oadadmins". 3. See above. 4. The only part that experiences an issue is the final "sm_reloadadmins" part. I'm not sure how I would use command line parameters for this, as once I run "screen -x" I'm no longer sending commands to putty, I'm sending them to the game server. I did use parameters for the username/password though. I tried to do the AppActivate trick as well, and it didn't change anything from above. Semi-functional code: Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run """C:\Program Files (x86)\PuTTY\putty.exe"" [email protected] -pw SUPERSECRETPASSWORD", 9 WScript.Sleep 3000 WshShell.SendKeys "screen -x" WshShell.SendKeys "{ENTER}" WScript.Sleep 1000 WshShell.AppActivate("[screen 0: srcds_run]") WshShell.SendKeys "sm_reloadadmins" WScript.Sleep 2000 WshShell.SendKeys "{ENTER}" WScript.Sleep 2000 EDIT: Now it manages to write "reloadadmins"... Quote 4. The only part that experiences an issue is the final "sm_reloadadmins" part. Code: [Select]WScript.Sleep 1000 WshShell.AppActivate("[screen 0: srcds_run]") WshShell.SendKeys "sm_reloadadmins" Try increasing the sleep parameter in this code block. Using sendkeys is more a balancing act than straight-up logic so you'll just have to PLAY around with the numbers until it works. How busy your machine and the game server are also factor into how smoothly the final script will run. I've tried modifying the sleep value before and after the appactivate, and the best I can get is _reloadadmins. I've even tried sending the SendKeys command more than once, even from different VBS files, and I still get the same problem. Since VBS was being such a pain in the and nothing I changed in the code had any effect, I moved on to AutoHotkey, which did the trick.A bit late to suggest this, but a heads up anyway: Tera Term is a terminal application with a built-in scripting language. It's idiosyncratic, but not difficult to learn. The benefit is that it runs in much the same way as an "expect" script, so you don't really need to think about wait/recheck. Well worth investigating: http://logmett.com/index.php?/products/teraterm.html |
|