@@ -69,26 +69,19 @@ std::vector<std::string> runcpp2::GetPlatformNames()
6969 #endif
7070}
7171
72- bool runcpp2::RunCommandAndGetOutput ( const std::string& command,
73- std::string& outOutput,
74- std::string runDirectory)
75- {
76- int returnCode;
77- return RunCommandAndGetOutput (command, outOutput, returnCode, runDirectory);
78- }
79-
80- bool runcpp2::RunCommandAndGetOutput ( const std::string& command,
81- std::string& outOutput,
82- int & outReturnCode,
83- std::string runDirectory)
72+ bool runcpp2::RunCommand ( const std::string& command,
73+ const bool & captureOutput,
74+ const std::string& runDirectory,
75+ std::string& outOutput,
76+ int & outReturnCode)
8477{
8578 ssLOG_FUNC_DEBUG ();
8679 ssLOG_DEBUG (" Running: " << command);
8780 System2CommandInfo commandInfo = {};
8881 if (!runDirectory.empty ())
8982 commandInfo.RunDirectory = runDirectory.c_str ();
9083
91- commandInfo.RedirectOutput = true ;
84+ commandInfo.RedirectOutput = captureOutput ;
9285 SYSTEM2_RESULT sys2Result = System2Run (command.c_str (), &commandInfo);
9386
9487 if (sys2Result != SYSTEM2_RESULT_SUCCESS)
@@ -98,20 +91,23 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
9891 }
9992 outOutput.clear ();
10093
101- do
94+ if (captureOutput)
10295 {
103- uint32_t byteRead = 0 ;
104- outOutput.resize (outOutput.size () + 4096 );
105-
106- sys2Result =
107- System2ReadFromOutput ( &commandInfo,
108- const_cast <char *>(outOutput.data ()) + outOutput.size () - 4096 ,
109- 4096 ,
110- &byteRead);
96+ do
97+ {
98+ uint32_t byteRead = 0 ;
99+ outOutput.resize (outOutput.size () + 4096 );
100+
101+ sys2Result =
102+ System2ReadFromOutput ( &commandInfo,
103+ const_cast <char *>(outOutput.data ()) + outOutput.size () - 4096 ,
104+ 4096 ,
105+ &byteRead);
111106
112- outOutput.resize (outOutput.size () + byteRead);
107+ outOutput.resize (outOutput.size () + byteRead);
108+ }
109+ while (sys2Result == SYSTEM2_RESULT_READ_NOT_FINISHED);
113110 }
114- while (sys2Result == SYSTEM2_RESULT_READ_NOT_FINISHED);
115111
116112 sys2Result = System2GetCommandReturnValueSync (&commandInfo, &outReturnCode, false );
117113 if (sys2Result != SYSTEM2_RESULT_SUCCESS)
@@ -120,7 +116,8 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
120116 return false ;
121117 }
122118
123- ssLOG_DEBUG (" outOutput: \n " << outOutput.c_str ());
119+ if (captureOutput)
120+ ssLOG_DEBUG (" outOutput: \n " << outOutput.c_str ());
124121
125122 if (outReturnCode != 0 )
126123 {
0 commit comments