User forums > Using Code::Blocks

Make commands

<< < (4/4)

sorinev:

--- Quote from: BlueHazzard on April 10, 2016, 08:48:40 pm ---You can also try to use scripting: http://wiki.codeblocks.org/index.php?title=Scripting_commands
the "ExecuteAndGetOutput" command should help.
For more reading:
http://wiki.codeblocks.org/index.php/Variable_expansion#Script_expansion

greetings

--- End quote ---

Trying to get this working, but having trouble.

Previously, I had this (although I had to recompile C::B to not use the backtick cache; I've since changed it back so I can try the scripting) under the #defines tab of project compiler settings, which works:


--- Code: ---BUILD_VERSION=\"`git describe --abbrev=5 --dirty --always --tags"`\"
--- End code ---

Following the example in the C::B project file (I think it's under Other compiler options) I changed it to this:


--- Code: ---BUILD_VERSION=\"[[IO.ExecuteAndGetOutput(_T("git describe --abbrev=5 --dirty --always --tags"))]]\"
--- End code ---

But it always comes out blank. I tried adding .ToStdString().c_str(), but it complained that they were unknown or undefined or something.

So following this example from the C::B project itself:


--- Code: ---[[if (GetCompilerFactory().GetCompilerVersionString(_T("gcc")) >= _T("4.8.0")) print(_T("-Wno-unused-local-typedefs"));]]
--- End code ---

I tried changing mine to this:


--- Code: ---BUILD_VERSION=\"[[print(_T(IO.ExecuteAndGetOutput(_T("git describe --abbrev=5 --dirty --always --tags"))))]]\"
--- End code ---

but it fails, with a messagebox saying:


--- Code: ---Filename: CommandLine
Error: Incorrect function argument
Details:
--- End code ---

(Details were blank). So, I'm not sure how to do this since finding examples regarding the [[]] ability is turning up next to nothing. I couldn't figure how to to use the "allowInsecureScripts" constant to see if the macro was defined, and I tried grepping for the macro itself but it was nowhere to be found except in sc_io.cpp, where it's only checked. Regardless, I removed the #ifndef and recompiled C::B just to test if ExecuteAndGetOutput was returning blank because of security, but it still returns blank.

BlueHazzard:
I added this

--- Code: ---TEST="[[print(IO.ExecuteAndGetOutput(_T("git --version")).RemoveLast(1))]]"
--- End code ---
into Project->Build options->#defines

and it seems to work

greetings

[EDIT:] Corrected the code!!!! No ticks!!!

sorinev:
I added the RemoveLast(1) part to my version (and removed the _T() part in print surrounding the ExecuteAndGetOutput()) and that seems to have been the issue. I never would have guessed that. Looking at the code, it seemed that it was just returning the plain result string already, but clearly not. Thanks.

BlueHazzard:
To clear things up:

--- Code: ---RemoveLast(1)
--- End code ---
is needed because ?git? (or ExecuteAndGetOutput?) gives a "\n" at the end and this will interfere with the gcc command

--- Code: ---_T()
--- End code ---
is only needed if you give native strings (closured in "") to a wxWidgets function

--- Code: ---print
--- End code ---
is needed to transfer the string value outside the [[]] script environment

greetings

[EDIT:]
To develop this code you can use the scripting console from view->Scripting Console

Navigation

[0] Message Index

[*] Previous page

Go to full version