irswat Posted January 27, 2017 Share Posted January 27, 2017 (edited) ;console and GetDXScanCode functions borrowed from ;http://www.gamesas.com/way-run-bat-from-script-t259754.html ;thanks Roberta Obrien, leigh stewart, and Allison Sizemore Function Console(String asCommand, Int aiCharIndex = 0, Int aiStringLength = 0) Input.TapKey(41) ; '~' aiStringLength = StringUtil.GetLength(asCommand) While (aiCharIndex < aiStringLength) Input.TapKey(GetDXScanCode(StringUtil.GetNthChar(asCommand, aiCharIndex))) aiCharIndex += 1 EndWhile Input.TapKey(28) ; 'Enter' Input.TapKey(41) ; '~' EndFunction Int Function GetDXScanCode(String asCharacter) If StringUtil.IsLetter(asCharacter) If asCharacter == "Q" Return 16 ElseIf asCharacter == "W" Return 17 ElseIf asCharacter == "E" Return 18 ElseIf asCharacter == "R" Return 19 ElseIf asCharacter == "T" Return 20 ElseIf asCharacter == "Y" Return 21 ElseIf asCharacter == "U" Return 22 ElseIf asCharacter == "I" Return 23 ElseIf asCharacter == "O" Return 24 ElseIf asCharacter == "P" Return 25 ElseIf asCharacter == "A" Return 30 ElseIf asCharacter == "S" Return 31 ElseIf asCharacter == "D" Return 32 ElseIf asCharacter == "F" Return 33 ElseIf asCharacter == "G" Return 34 ElseIf asCharacter == "H" Return 35 ElseIf asCharacter == "J" Return 36 ElseIf asCharacter == "K" Return 37 ElseIf asCharacter == "L" Return 38 ElseIf asCharacter == "Z" Return 44 ElseIf asCharacter == "X" Return 45 ElseIf asCharacter == "C" Return 46 ElseIf asCharacter == "V" Return 47 ElseIf asCharacter == "B" Return 48 ElseIf asCharacter == "N" Return 49 ElseIf asCharacter == "M" Return 50 EndIf ElseIf StringUtil.IsDigit(asCharacter) If asCharacter == "1" Return 2 ElseIf asCharacter == "2" Return 3 ElseIf asCharacter == "3" Return 4 ElseIf asCharacter == "4" Return 5 ElseIf asCharacter == "5" Return 6 ElseIf asCharacter == "6" Return 7 ElseIf asCharacter == "7" Return 8 ElseIf asCharacter == "8" Return 9 ElseIf asCharacter == "9" Return 10 ElseIf asCharacter == "0" Return 11 EndIf ElseIf asCharacter == " " Return 57 ElseIf asCharacter == "-" Return 12 ElseIf asCharacter == "=" Return 13 ElseIf asCharacter == "[" Return 26 ElseIf asCharacter == "]" Return 27 ElseIf asCharacter == ";" Return 39 ElseIf asCharacter == "'" Return 40 ElseIf asCharacter == "~" Return 41 ElseIf asCharacter == "," Return 51 ElseIf asCharacter == "." Return 52 ElseIf asCharacter == "/" Return 53 ElseIf asCharacter == " " Return 57 EndIf EndFunction bool function DumpLog() float time string log string timeLogFileName string filePath time=Utility.GetCurrentRealTime() timeLogFileName=(time as string) string sDatafileName ;gets My documents location Console("Bat GetPath.bat") sDatafileName = "SVCE/filePath.txt" if MiscUtil.FileExists(sDatafileName) debug.trace("File found: reading file.") filePath = MiscUtil.ReadFromFile(sDatafileName) endif ;sets path to papyrus trace log sDatafileName = filePath + "/My Games/Skyrim/Logs/Script/Papyrus.0.log" ;dumps contents of tracelog to a string if MiscUtil.FileExists(sDatafileName) debug.trace("File found: reading file.") log = MiscUtil.ReadFromFile(sDatafileName) endif ;sets write file path to current time stamp debug.trace("dumping from " + sDatafileName + " to " + "/logs/" + time + ".txt") sDatafileName = "SVCE/logs/" + timeLogFileName + ".txt" ;writes log to timstamped file in SVCE folder MiscUtil.WriteToFile(sDatafileName, log, false, false) return true endFunction Now it opens the console. And i've seen it type letters, but for some reason using the console command to run the bat file doesn't work. The bat file itself works. It simply retrieves the documents path from registry and saves it to a text file. If I run the bat manually using bat "GetPath.bat" before executing this LogDump function, the log function works perfect. Something about the console function isn't working, but others have reported success with it. Edited January 27, 2017 by irswat Link to comment Share on other sites More sharing options...
PeterMartyr Posted January 27, 2017 Share Posted January 27, 2017 consider using ConsoleUtil to run the bat with one line of code, without opening the console ; Execute command in console silently. ;function ExecuteCommand(string text) global native ConsoleUtil.ExecuteCommand("Bat GetPath") It's bad luck MiscUtil doesn't run a bat since 2.9, since you have it. :ermm: (Had too Check, I haven't use it since 2.8 so was having a What The (F) Moment, while reading your post. :confused: ) Good luck on your Mod. ConsoleUtil is by Meh321 the original author of PapyrusUtil. Cheers Link to comment Share on other sites More sharing options...
cdcooley Posted January 27, 2017 Share Posted January 27, 2017 If I had to guess it would be that you've closed the console before the command was processed. If that's it a small wait just after the TapKey(28) should fix it. But using ConsoleUtil would probably be a better option. Link to comment Share on other sites More sharing options...
irswat Posted January 27, 2017 Author Share Posted January 27, 2017 great advice thanks guys! I would rather not use the bat option, but ultimately I'm planning on using a bat file to dump dir content to import mod support. Link to comment Share on other sites More sharing options...
irswat Posted January 28, 2017 Author Share Posted January 28, 2017 actually, it's weird, it's like the TapKey command doesn't work when the console is open. The function opens the console (taps ~), then nothing, but if i hit tilde again, the script then presses the buttons. Link to comment Share on other sites More sharing options...
irswat Posted January 28, 2017 Author Share Posted January 28, 2017 how can I do this:ConsoleUtil.ExecuteCommand("Bat /SVCE/GetPath") I have the bat file in a separate directory Link to comment Share on other sites More sharing options...
irswat Posted January 28, 2017 Author Share Posted January 28, 2017 it seems the console command bat does not do what it suggests. My bat file is supposed to check a registry key to find the location of the documents folder, in order to copy the papyrus log. The bat command seems to only support bat files that contain skyrim console commands. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 28, 2017 Share Posted January 28, 2017 Where did you get the idea that a bat file for use in Skyrim's console could do more than just what is capable from Skyrim's console? Link to comment Share on other sites More sharing options...
irswat Posted January 28, 2017 Author Share Posted January 28, 2017 (edited) I assumed batch files are executed by windows. Apparently these are not batch files, but simply text files that get read into skyrim. Would be so cool if there were a way to execute batch files from console. So many possibilities. Maybe via an skse plugin Edited January 28, 2017 by irswat Link to comment Share on other sites More sharing options...
irswat Posted January 28, 2017 Author Share Posted January 28, 2017 (edited) I wonder what would happen if I used setmodelpath to a batch file. Edited January 29, 2017 by irswat Link to comment Share on other sites More sharing options...
Recommended Posts