...In command prompt, I can type "PrintArgument %VAR%" and the output will be "abc". ....
Does this works already when you run your program under command line?
Yes. The code for the PrintArgument program is just as follows:
int main(int argc, char* argv[])
{
cout << argv[1] << endl;
return 0;
}
In other words, it's the command prompt that looks up the value of %VAR% (which is "abc") and passes the value into my program.
If the answer is Yes, this means your program can do the job which replace %VAR% to abc, and print the abc.
If the answer is No, this means your program can NOT do the job, then why do you ask C::B to do the job? In this case, It is definitely a problem of your program, not C::B.
PrintArgument is just my made-up program to help illustrate my question. I have a much larger program in which a value of an environment variable is required to be passed. Although I can compile the program in C::B and run it using command prompt, it would be more convenient if I can do both in C::B. Hence, I was wondering if C::B allows me to achieve this. I'll find other alternatives if this is not possible.
Thanks ollydbg for your speedy reply. ;)
Although I can compile the program in C::B and run it using command prompt, it would be more convenient if I can do both in C::B. Hence, I was wondering if C::B allows me to achieve this. I'll find other alternatives if this is not possible.
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)
cmd /c $(TARGET_NAME) %VAR%
See: http://wiki.codeblocks.org/index.php?title=Variable_expansion as another reference.
EDIT:
Variables which are neither global user variables nor builtin types are replaced with a value provided in the project file, or with an environment variable if the latter should fail.
So, maybe, C::B already replace the %XXX% like string reference to Variable expansion - CodeBlocks (http://wiki.codeblocks.org/index.php?title=Variable_expansion), so just enable the macro replace feature for the argument input dialog?
At least on linux, the environment variables get expanded:
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
for (int i=0; i < argc; ++i)
cout << argv[i] << endl;
cout << "Hello world!" << endl;
return 0;
}
called with argument $HOME (set in "Project -> Set programs's arguments..." gives the (expected) result:
/tmp/test/bin/Debug/test
/home/jens
Hello world!
Process returned 0 (0x0) execution time : 0.002 s
Press ENTER to continue.