User forums > Using Code::Blocks

Passing environment variables as programs' arguments

<< < (2/2)

qweweng:

--- Quote from: ollydbg on November 13, 2013, 04:02:01 pm ---Ok, I think C::B don't have this feature(expand the %VAR% string to its value in its argument settings)
You can enhance it by implement it, so patch are welcome.
Another way I think you can use is to use the Tool+ plugin, which you can use the command line tool, you can see a related discuss here:
http://developer.berlios.de/bugs/?func=detailbug&bug_id=19180&group_id=5358

So, write some command like (I don't try this yet, you can try it yourself)


--- Code: ---cmd /c $(TARGET_NAME) %VAR%

--- End code ---

See: http://wiki.codeblocks.org/index.php?title=Variable_expansion as another reference.

--- End quote ---

Thanks to your suggestions, I got 2 workarounds to this problem:
1. Post-build Steps
    (a) Go to the Project's Build Options, select the "Pre/post build steps" tab.
    (b) Under Post-build step, type "$(TARGET_OUTPUT_FILE) %VAR%".
    (c) Check "Always execute, even if target is up-to-date"
    (d) Build the project. Due to (c), the executable will run regardless of whether it's up-to-date, which is what I want.
         * If we "Build and Run" the project, the executable will run twice.

2. External Tool
    (a) Go to Tools -> Configure tools, click Add to create a new tool.
    (b) Fill up the Edit tool dialog. For my case, the data is as follows:
         Name:            Whatever
         Executable:     ${TARGET_OUTPUT_FILE}
         Parementers:   %VAR%
         Working directory: ${PROJECT_DIR}
    (c) Go to Tools and click Whatever to run the program.

Though these are not the most desired ways, but it's good enough for me. ;)


--- Quote from: ollydbg on November 13, 2013, 04:02:01 pm ---EDIT:
So, maybe, C::B already replace the %XXX% like string reference to Variable expansion - CodeBlocks, so just enable the macro replace feature for the argument input dialog?

--- End quote ---

Somehow I couldn't find the "enable the macro replace feature" in the argument input dialog. Did I miss something?


--- Quote from: jens on November 14, 2013, 07:27:54 am ---At least on linux, the environment variables get expanded:

--- Code: ---#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    for (int i; i < argc; ++i)
        cout << argv[i] << endl;
    cout << "Hello world!" << endl;
    return 0;
}

--- End code ---
called with argument $HOME (set in "Project -> Set programs's arguments..." gives the (expected) result:

--- Quote ---/tmp/test/bin/Debug/test
/home/jens
Hello world!

Process returned 0 (0x0)   execution time : 0.002 s
Press ENTER to continue.

--- End quote ---

--- End quote ---

Thanks. Too bad I'm not using Linux. Tried everything I could with the program's argument but it just doesn't work.

ollydbg:
Glad you find at least two methods.

--- Quote from: qweweng on November 14, 2013, 02:49:29 pm ---Somehow I couldn't find the "enable the macro replace feature" in the argument input dialog. Did I miss something?
--- End quote ---
No such option in C::B, as Jen's test shown that under Linux, environment variables get expanded correctly.


--- Quote ---Too bad I'm not using Linux. Tried everything I could with the program's argument but it just doesn't work.

--- End quote ---
So, as your testing result, environment variables do not get expanded under Windows for C::B's program argument.

Navigation

[0] Message Index

[*] Previous page

Go to full version