Computing.Net > Forums > Programming > C Program System()

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C Program System()

Reply to Message Icon

Name: cool_andy
Date: May 14, 2007 at 03:06:40 Pacific
OS: Windows XP
CPU/Ram: 512
Product: Acer
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: May 14, 2007 at 04:53:25 Pacific
Reply:

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.


0

Response Number 2
Name: cool_andy
Date: May 14, 2007 at 06:11:34 Pacific
Reply:

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.h

I 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.txt

Thanks again for your help

Andrew Ashcroft


0

Response Number 3
Name: IVO
Date: May 14, 2007 at 06:58:04 Pacific
Reply:

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.


0

Response Number 4
Name: cool_andy
Date: May 16, 2007 at 03:26:58 Pacific
Reply:

Ok, when I do system("prop output.txt");

It just displays the text:
off
set /P zdir=
ss properties "" -O@version.txt

prop.bat contains:
@echo off
set /P zdir=< %1
ss properties "%zdir%" -O@version.txt

I dont understand why it does not run any of the commands above?

Andrew


0

Response Number 5
Name: IVO
Date: May 16, 2007 at 06:06:59 Pacific
Reply:

Before I start a boring lesson about command processors, try rhis

system("cmd /C prop output.txt");

and report what you get.



0

Related Posts

See More



Response Number 6
Name: cool_andy
Date: May 16, 2007 at 09:49:12 Pacific
Reply:

system("cmd /C prop output.txt");

This runs prop.bat successfully.
It reports the properties of the directory path given in output.txt

Example:
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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C Program System()

java system call to C++ program www.computing.net/answers/programming/java-system-call-to-c-program/10126.html

running C programs www.computing.net/answers/programming/running-c-programs/3587.html

C Programming Problem , www.computing.net/answers/programming/c-programming-problem-/942.html