MCPcopy Create free account
hub / github.com/SpartanJ/eepp / openExternal

Function openExternal

src/tools/ecode/terminalmanager.cpp:425–500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423}
424
425static int openExternal( const std::string& defShell, const std::string& cmd,
426 const std::string& scriptsPath, const std::string& workingDir ) {
427 // This is an utility bat script based in the Geany utility script called "geany-run-helper"
428 static const std::string_view RUN_HELPER =
429 R"shellscript(REM USAGE: ecode-run-helper DIRECTORY AUTOCLOSE COMMAND...
430
431REM unnecessary, but we get the directory
432cd %1
433shift
434REM save autoclose option and remove it
435set autoclose=%1
436shift
437
438REM spawn the child
439REM it's tricky because shift doesn't affect %*, so hack it out
440REM https://en.wikibooks.org/wiki/Windows_Batch_Scripting#Command-line_arguments
441set SPAWN=
442:argloop
443if -%1-==-- goto argloop_end
444 set SPAWN=%SPAWN% %1
445 shift
446goto argloop
447:argloop_end
448%SPAWN%
449
450REM show the result
451echo:
452echo:
453echo:------------------
454echo:(program exited with code: %ERRORLEVEL%)
455echo:
456
457REM and if wanted, wait on the user
458if not %autoclose%==1 pause
459 )shellscript";
460 if ( !cmd.empty() && !scriptsPath.empty() ) {
461 std::string runHelperPath = scriptsPath + "ecode-run-helper.bat";
462 bool canContinue = true;
463 if ( !FileSystem::fileExists( runHelperPath ) &&
464 !FileSystem::fileWrite( runHelperPath, RUN_HELPER ) ) {
465 canContinue = false;
466 }
467 if ( canContinue ) {
468 std::string cmdDir = String::trim( FileSystem::fileRemoveFileName( cmd ) );
469 if ( cmdDir.empty() )
470 cmdDir = workingDir;
471 std::string cmdFile = String::trim( FileSystem::fileNameFromPath( cmd ) );
472 auto fcmd = "cmd.exe /q /c " + quoteString( "\"" + runHelperPath + "\" \"" + cmdDir +
473 "\" 0 \"" + cmdFile + "\"" );
474 Log::info( "Running: %s", fcmd );
475 return Sys::execute( fcmd, workingDir );
476 } else {
477 Log::info( "Couldn't write runHelperPath %s", runHelperPath );
478 }
479 }
480
481 std::vector<std::string> options;
482 options.reserve( 3 );

Callers 2

displayErrorMethod · 0.85

Calls 6

quoteStringFunction · 0.85
infoFunction · 0.85
executeFunction · 0.85
reserveMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected