Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Script plugin : IO.Execute(cmd)
LETARTARE:
@MortenMacFly
I made many tests on this version with r7822
--- Code: ---wxString ExecuteAndGetOutputAndError(const wxString& command)
{
if (!SecurityAllows(_T("Execute"), command))
return wxEmptyString;
wxArrayString output;
wxArrayString error;
wxString str_out;
wxExecute(command, output, error, wxEXEC_NODISABLE);
// first 'stderr'
if (!error.IsEmpty())
str_out += _T("stderr :\n") + GetStringFromArray(error, _T("\n"));
if (!output.IsEmpty())
str_out += _T("stdout :\n") + GetStringFromArray(output, _T("\n"));
return str_out;
}
--- End code ---
especially for simultaneously 'sdtout' and 'stderr' (the latter with warnings and errors)
I put 'stderr' at the start to test it first.
what do you think?
MortenMacFly:
--- Quote from: LETARTARE on February 24, 2012, 09:36:11 am ---what do you think?
--- End quote ---
If it works - nice. All I would do (I forgot in the first place) is to have a flag to specify how you want the errors to appear. So the interface could be like:
wxString ExecuteAndGetOutput(const wxString& command, bool prepend_error = true)
This would enable you to get what you want in the order you want (pre-pended / appended).
Besides I'd rather not change the output of the executable by pre-pending "stdout/stderr". Because if you expect a certain output you want to operate on this will screw it otherwise.
EDIT: BTW: I just looked at you patch: I still don't believe you need an additional function. I thought you'd do it by extending the existing one?!
LETARTARE:
@MortenMacFly
--- Quote ---BTW: I just looked at you patch: I still don't believe you need an additional function. I thought you'd do it by extending the existing one?!
--- End quote ---
I had not read the correction message!, but of course this is possible.
I have considered your suggestion.
In my case 'stderr' can give me an ERROR or just a WARNING without error.
But it is the reading 'stderr' can I know!
If it's only a warning, I also need to read 'stdout'.
If it is an error, 'sdtout' will be empty.
This is why I commented on the 'else'.
In this version, I can either get or not the errors / warnings
With the command, I can always choose to use 'stdout or not
--- Code: ---wxString ExecuteAndGetOutputAndError(const wxString& command, bool prepend_error = false)
{
if (!SecurityAllows(_T("Execute"), command))
return wxEmptyString;
wxArrayString output;
wxArrayString error;
wxString str_out;
wxExecute(command, output, error, wxEXEC_NODISABLE);
// first 'stderr'
if (prepend_error && !error.IsEmpty())
str_out += _T("stderr :\n") + GetStringFromArray(error, _T("\n"));
//else
if (!output.IsEmpty())
str_out += _T("stdout :\n") + GetStringFromArray(output, _T("\n"));
return str_out;
}
--- End code ---
MortenMacFly:
--- Quote from: LETARTARE on February 24, 2012, 12:53:38 pm ---This is why I commented on the 'else'.
--- End quote ---
I guess there was a slight mis-understanding. What I mean was something like this:
--- Code: --- wxString ExecuteAndGetOutputAndError(const wxString& command, bool prepend_error = true)
{
if (!SecurityAllows(_T("Execute"), command))
return wxEmptyString;
wxArrayString output;
wxArrayString error;
wxExecute(command, output, error, wxEXEC_NODISABLE);
wxString str_out;
if (prepend_error && !error.IsEmpty())
str_out += GetStringFromArray(error, _T("\n"));
if (!output.IsEmpty())
str_out += GetStringFromArray(output, _T("\n"));
if (!prepend_error && !error.IsEmpty())
str_out += GetStringFromArray(error, _T("\n"));
return str_out;
}
--- End code ---
(UNTESTED!)
As you see, I just wanted to give the user an option to append or prepend errors - depending what he believes is the best option to merge stdout and stderr. As errors are generally more important (and if not the user will use ExecuteAndGetOutput anyways) the default setting should be to pre-pend. Also, I skipped _T("stderr :\n") and _T("stdout :\n") as this screws the real output.
LETARTARE:
Actually, I did not understand your intention to 'sdterr' before or after 'stdout'.
I just test it, it works well.
But after the removal of marks separating, I can not separate the flow 'stderr' and 'stdout',
especially in the case or 'stderr' provides me with warnings.
But it's better than nothing.
Thank you very much for your availability.
Especially with the number of patches that you realize right now.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version