1 /* _______________________________________________________________________ 2 3 DAKOTA: Design Analysis Kit for Optimization and Terascale Applications 4 Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 5 This software is distributed under the GNU Lesser General Public License. 6 For more information, see the README file in the top Dakota directory. 7 _______________________________________________________________________ */ 8 9 //- Class: CommandShell 10 //- Description: Class implementation 11 //- Owner: Bill Bohnhoff 12 13 #include "CommandShell.hpp" 14 #include "WorkdirHelper.hpp" 15 #include "dakota_global_defs.hpp" 16 17 static const char rcsId[]="@(#) $Id: CommandShell.cpp 7021 2010-10-12 22:19:01Z wjbohnh $"; 18 19 20 namespace Dakota { 21 22 /** Executes the sysCommand by passing it to system(). Appends an 23 "&" if asynchFlag is set (background system call) and echos the 24 sysCommand to Cout if suppressOutputFlag is not set. */ flush()25CommandShell& CommandShell::flush() 26 { 27 if (asynchFlag) { 28 #if !defined(_MSC_VER) 29 sysCommand += " &"; 30 #else 31 // using /B to keep the started command in the same Command Prompt 32 sysCommand = "start \"SystemInterface-Evaluation\" /B " + sysCommand; 33 #endif 34 } 35 36 if (!suppressOutputFlag) 37 Cout << sysCommand << std::endl; // output the cmd string for verification 38 39 #ifdef HAVE_SYSTEM 40 std::system(sysCommand.c_str()); 41 #else 42 Cout << "ERROR: attempting to use a system call on a system that does" 43 << " NOT support system calls" << std::endl; 44 abort_handler(-1); 45 #endif 46 47 sysCommand.clear(); 48 return *this; 49 } 50 51 52 /** global convenience function for manipulating the shell; invokes 53 the class member flush function. */ flush(CommandShell & shell)54CommandShell& flush(CommandShell& shell) 55 { 56 shell.flush(); 57 return shell; 58 } 59 60 } // namespace Dakota 61