diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index aff8045e..88691abb 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -125,21 +125,29 @@ AutoexecObject::~AutoexecObject(){ // Remove the line from the autoexecbuffer and update environment for(auto_it it = autoexec_strings.begin(); it != autoexec_strings.end(); ) { - if((*it) == buf) { - it = autoexec_strings.erase(it); + if ((*it) == buf) { std::string::size_type n = buf.size(); char* buf2 = new char[n + 1]; safe_strncpy(buf2, buf.c_str(), n + 1); + bool stringset = false; // If it's a environment variable remove it from there as well - if((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){ + if ((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){ char* after_set = buf2 + 4;//move to variable that is being set char* test = strpbrk(after_set,"="); - if(!test) continue; + if (!test) continue; *test = 0; + stringset = true; //If the shell is running/exists update the environment - if(first_shell) first_shell->SetEnv(after_set,""); + if (first_shell) first_shell->SetEnv(after_set,""); } delete [] buf2; + if (stringset && first_shell && first_shell->bf && first_shell->bf->filename.find("AUTOEXEC.BAT") != std::string::npos) { + //Replace entry with spaces if it is a set and from autoexec.bat, as else the location counter will be off. + *it = buf.assign(buf.size(),' '); + it++; + } else { + it = autoexec_strings.erase(it); + } } else it++; } this->CreateAutoexec();