Quick Question about ScriptDragon.
When using: ExecuteConsoleCommand(), most console commands execute fine. However if I try to use the "bat" command, it doesn't seem to go through. (Improper usage of the command will return the regular error message in the console. However correct usage does nothing and produces no result). The strange part is that it will work, if the console has been opened at least once before the plugin runs. (Even if you just open the close, at say the main menu). Not sure if its' a quirk of Skyrim, or glitch in ScriptDragon, so figured I'd ask.
I encountered this problem as well when writing my SD plugin to execute Skyrim batch files automatically (ZAE, in my signature) and my workaround was to write my own batch execution function.
i.e.; Open & parse the batch file and send each line in the file as a command one-by-one using ExecuteConsoleCommand() instead of trying to use the built-in 'bat' command.
Example from ZAE:
// ========================================// ExecuteBatch// ========================================void ZBatchFile::Execute(){ // Open batch file stream std::ifstream file (sBatch); if (file.is_open()) { std::string line; while ( file.good() ) { // Read line from text file into string getline (file,line); // Convert std::string to char array. Extra step for safety to avoid overflow. char * command = new char [line.size()+1]; strcpy (command, line.c_str() ); // Execute the command through the console. ExecuteConsoleCommand( command, 0 ); // Free dynamic memory to avoid leak delete[] command; } // Close batch file file.close(); }}
sBatch is just a string containing a batch file's name.
The char*/string conversions are just me being equal parts messy and pedantic; so that could probably be simplified.