I've been fascinated by the simplicity of batch files for quite some time, but now I'm trying to expand their capabilities.
The first thing I've tried is a simple randomizer. It works quite well if I just return the random integer, then use 'if errorlevel' in the batch file, but to make things easier, I wanted to allow the randomizer to directly set a variable in the console.
To do this, I tried
which did not work, even though printing setcmd showed it held the right console command.Code:if (argv[3] != '\0') { snprintf(setcmd, sizeof(setcmd), "set %s=%d", argv[3], r); system(setcmd); }
The weird thing is, other commands such as "echo Foo" and "cls" work, it's just "set var=num" that doesn't.
Any explanation as to why it is so and/or how to go around it would be much appreciated.



LinkBack URL
About LinkBacks



. There is a way to change environment variable of the calling program. See
) but I must have forgotten about it. I'll give it a spin tho.