News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Unable to use %RANDOM% in Project->Set programs' arguments

Started by Morwenn, June 04, 2017, 03:57:22 PM

Previous topic - Next topic

Morwenn

One of my projects has a test suite that uses the testing framework Catch. Catch has a command line option --rng-seed to seed the random number generator, and I want to use it with a random seed. In order to achieve that I tried to run the compiled test suite project as follows (Windows 10):

testsuite.exe --rng-seed %RANDOM%

Seeing that it worked fine, I decided to pass the same parameter directly to my Code::Blocks project through "Project->Set programs' arguments". However, when I give the command-line parameter --rng-seed %RANDOM% to Code::Blocks, the command line parser actually receives the string %RANDOM% instead of the corresponding integer. Is there a way to circumvent this problem and have Code::Blocks evaluate %RANDOM% instead of passing it as a string?

oBFusCATed

What is %RANDOM%? Environment variable? Some batch built-in function?
Does it work if you use start in the cmd to execute the command?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Morwenn

It's the rough equivalent of Unix $RANDOM: it's an environment variable automatically replaced by a random integer.
It does work if I start the cmd to execute the command.

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Morwenn

I just tried with the four different variable syntaxes described in the linked page, but none worked.

stahta01

Quote from: Morwenn on June 04, 2017, 03:57:22 PM
testsuite.exe --rng-seed %RANDOM%

I sometimes have to add CMD /C prefix for some things; I suggect trying it like.

CMD /C testsuite.exe --rng-seed %RANDOM%
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Morwenn

Quote from: stahta01 on June 04, 2017, 04:53:28 PM
I sometimes have to add CMD /C prefix for some things; I suggect trying it like.

CMD /C testsuite.exe --rng-seed %RANDOM%

The command line I've shared in my first post works perfectly fine. The problem is when I give the parameters through Code::Blocks "Projects->Set programs' arguments", whose interfacce does not provide a full access to the command-line, so I can't add things prior to the executable name with this interface.

oBFusCATed

Then I guess you'll need to open a ticket on the sf.net project page, so this problem is not forgotten.
But I'm surprised that it doesn't work. I think we added variable expansion there.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Morwenn