Author Topic: Unable to use %RANDOM% in Project->Set programs' arguments  (Read 419 times)

Offline Morwenn

  • Multiple posting newcomer
  • *
  • Posts: 13
Unable to use %RANDOM% in Project->Set programs' arguments
« on: June 04, 2017, 03:57:22 pm »
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):

Code: [Select]
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10277
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #1 on: June 04, 2017, 04:04:27 pm »
What is %RANDOM%? Environment variable? Some batch built-in function?
Does it work if you use start in the cmd to execute the command?
<debugger plugin maintainer>
(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!]

Offline Morwenn

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #2 on: June 04, 2017, 04:07:20 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10277
<debugger plugin maintainer>
(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!]

Offline Morwenn

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #4 on: June 04, 2017, 04:47:20 pm »
I just tried with the four different variable syntaxes described in the linked page, but none worked.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 5943
    • My Best Post
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #5 on: June 04, 2017, 04:53:28 pm »
Code: [Select]
testsuite.exe --rng-seed %RANDOM%

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

Code: [Select]
CMD /C testsuite.exe --rng-seed %RANDOM%
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Morwenn

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #6 on: June 04, 2017, 04:56:58 pm »
I sometimes have to add CMD /C prefix for some things; I suggect trying it like.

Code: [Select]
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10277
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #7 on: June 04, 2017, 05:14:18 pm »
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.
<debugger plugin maintainer>
(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!]

Offline Morwenn

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Unable to use %RANDOM% in Project->Set programs' arguments
« Reply #8 on: June 05, 2017, 12:06:47 pm »
Ok, I'll open a ticket on Sourceforge then.