Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
In my C Program I have system calls to execute DOS commands and Visual Sourcesafe commands.
This one works ok
system("set");However if I try to set a variable nothing seems to happen?
//sets test varaible to 3
system("set ztest= 3");//gets first line in textfile
system("set /P zdir= < output.txt");This command however for Souresafe does work
system("ss properties \"$/EPCS Base Components/Miscellaneous/Menu Conversion/lib.h\" -O@version.txt");If if I could I successfully run the SET command above to store the first line, then I would be able to run this one directly after:
system("ss properties \"%zdir%\" -O@version.txt");I have noticed the '\' the back slashes seem to print the characters which are required, like the '"' in the command above. Is this perhaps required in SET user variables?
Maybe something like?
system("set \/P zdir= < output.txt");Or maybe forward slash '/' because /P is a flag which is needed to get the first line?
I could be completely wrong but any help is much appreciated.
Thank you
Andrew Ashcroft

The problem you are facing with Set is due to the dynamic of child environments: when you issue a system("...") statement a secondary command processor is invoked to perform the required action and a new environment is built. That inherites the native one, but any change operated on it is lost at command completion. So you can't set variables this way as they are not retained from one call to the other.

Ok, would it be possible to run a batch file in system()?
For example:
system("properties");
or
system("call properties.bat")If not, I will have to find some alternative way.
Basically what I want to do is execute this sourcesafe command.
This one already works:
system("ss properties \"$/EPCS Base Components/Miscellaneous/Menu Conversion/lib.h\" -O@version.txt");I would like to substitute the directory with:
system("ss properties "variable" -O@version.txt");The variable will store the directory path:
$/EPCS Base Components/Miscellaneous/Menu Conversion/lib.hI could do this using a %variable%, but it would be even better if I can use a C char variable within System()?
If I wanted to use %variable%, thats why I need to execute set /P zdir= < output.txtThanks again for your help
Andrew Ashcroft

Yes, you can run a whole batch by the System() statement and in that way you can manipulate variables in its environment.
To follow your code you could set up
system("prop output.txt")
where prop.bat accept the output.txt content by
Set /P zdir=< %1
being %1 matched with output.txt at run time.
You can use a string variable as argument of system() and set the string by C code.

Ok, when I do system("prop output.txt");
It just displays the text:
off
set /P zdir=
ss properties "" -O@version.txtprop.bat contains:
@echo off
set /P zdir=< %1
ss properties "%zdir%" -O@version.txtI dont understand why it does not run any of the commands above?
Andrew

Before I start a boring lesson about command processors, try rhis
system("cmd /C prop output.txt");
and report what you get.

system("cmd /C prop output.txt");
This runs prop.bat successfully.
It reports the properties of the directory path given in output.txtExample:
File: $/EPCS Base Components/pclib/lib.h
Type: Text
Size: 29418 bytes 787 lines
Store only latest version: No
Latest:
Version: 94
Date: 15/03/07 11:38
Comment:Thank you for your help

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |