Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Script plugin : IO.Execute(cmd)

(1/4) > >>

LETARTARE:
reference : http://wiki.codeblocks.org/index.php?title=Scripting_commands#IO_namespace
In a script plugin during the use of

--- Code: ---local int_err = ::IO.Execute(cmd)
local str_out = ::IO.ExecuteAndGetOutput(cmd)
--- End code ---
can not retrieve messages from any errors in 'cmd'
I also propose

--- Code: ---local str_error = ::IO.ExecuteAndGetError (cmd)
--- End code ---

Is it possible to make this fix ?

--- Code: ---Index: src/sdk/scripting/bindings/sc_io.cpp
===================================================================
--- src/sdk/scripting/bindings/sc_io.cpp (révision 7820)
+++ src/sdk/scripting/bindings/sc_io.cpp (copie de travail)
@@ -188,6 +188,16 @@
             return wxExecute(command, output, wxEXEC_NODISABLE);
         }
 
+ wxString ExecuteAndGetError(const wxString& command)
+        {
+            if (!SecurityAllows(_T("Execute"), command))
+                return wxEmptyString;
+            wxArrayString output;
+            wxArrayString error;
+            wxExecute(command, output, error, wxEXEC_NODISABLE);
+            return GetStringFromArray(error, _T("\n"));
+        }
+
         wxString ExecuteAndGetOutput(const wxString& command)
         {
             if (!SecurityAllows(_T("Execute"), command))
@@ -216,7 +226,10 @@
                 staticFunc(&IOLib::RemoveFile, "RemoveFile").
                 staticFunc(&IOLib::WriteFileContents, "WriteFileContents").
                 staticFunc(&IOLib::Execute, "Execute").
+                staticFunc(&IOLib::ExecuteAndGetError, "ExecuteAndGetError").
                 staticFunc(&IOLib::ExecuteAndGetOutput, "ExecuteAndGetOutput").
+
+
                 #endif // NO_INSECURE_SCRIPTS
 
                 staticFunc(&IOLib::GetCwd, "GetCwd").

--- End code ---

MortenMacFly:

--- Quote from: LETARTARE on February 21, 2012, 04:04:38 pm ---Is it possible to make this fix ?

--- End quote ---
Yes, but why don't you change the existing signature to return both: stdout and stderr instead of two? In your case, I would have to launch an application twice to get both messages which is not only lengthy, but may also result in different outputs.

LETARTARE:
yes, but I do not see how, because it returns a single table?

MortenMacFly:

--- Quote from: LETARTARE on February 21, 2012, 04:20:31 pm ---yes, but I do not see how, because it returns a single table?

--- End quote ---
Well an easy way would be to have a boolean flag for that function "include_errors", which is false by default, and then append (or probably pre-pend) the errors to the string you return if it is true.

LETARTARE:
@ MortenMacFly
thank you, I will try.

Navigation

[0] Message Index

[#] Next page

Go to full version