Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use of SYSTEM() command

Status
Not open for further replies.

LFI

Programmer
Apr 27, 1999
1,996
0
0
US
I've been going through the SAM's "Teach Yourself C in 21 Days" book (which I tend to like) and when trying to compile sample programs with the SYSTEM() function in it, I received error messages indicating that my Borland C compiler didn't recognize this function (even though I had included the STDLIB.H file in my #include statements at the beginning.<br>
<br>
Has this happened to any of you before? I thought the SYSTEM() function was ANSI standard and should be recognized. Hmmm...
 
I'm not an expert, but I think that the system() funtion is not implementable on a win32 system...<br>
Please correct me if I'm wrong! ;)
 
Thanks for the reply. I have Windows '95. Are you saying that I need to compile my program with Windows closed (i.e., from DOS)? I'll try anything, but remember, I'm not even up to the point where I'm running the program. I can't even compile. Suggestions?
 
Hmmm... <br>
I'm not sure here... as I said, I'm not an expert by any means!<br>
What I meant was that the system() may not be available on machines running MS-DOS/Windows as an OS.<br>
(But it's probably available on UNIX OS's (Like Linux) )<br>
<br>
I'm more of a Perl programmer.. (novice!!)<br>
<br>
Can anyone else help out here?
 
System() is a system specific function. Therefore, if you're your going to use it, then you must include a header file that contains the hooks to the 'system' you're running. A unix environment is going to have different system calls than say a DOS environemnt.<br>
<br>
As I understand it the ANSI std syslib is a c/unix standard, and does not understand Win-95, or DOS or BIOS. Therefore, a header file should be included in the compile that describes the system specific commands (and structures) that are avialable. If you're developing a 'C' program for a Windows platform, then you need the SDK that contains the .h files for getting to the system. For example, if your developing database code for use with an Informix databse, then you will need the Informix libraries and header files, otherwise you will have to develop them for yourself.
 
I'm using Borland C version 5.01 on NT, and a test program containing the system() call has different results depending on the target selected.<br>
<br>
For a Win32 or DOS target the program compiles fine. However, for a Windows 3.x target it fails to link because it cannot find system(). A check on the help tells me that system() is available on DOS, Unix, Win32 and OS/2, but not Win16 or ANSI C. <br>
<br>
What target do you have selected for your program? If it is Windows 3.x try changing it and seeing if that helps.
 
System() function is an ANSI compatible function . So it must work at every system . What matters is in which header file it is located. You just include both the header files: &lt;process.h&gt; &lt;stdlib.h&gt;.<br>
Does it answer your question ?<br>
Thanx<br>
Siddhartha Singh<br>
<A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
i dont know how to use the system command with a variable under the windows, for example

char *variable=&quot;value&quot;;
system(&quot;mddriver variable&quot;);

so i need to execute &quot;mddriver value&quot; on command line not
&quot;mddriver variable&quot; thanx for help..
 
rare, i use lcc-win32 and the system() function works fine with win2000 and win98.

Code:
#include <stdio.h>
#include <stdlib.h>

void main(void){

  char cmd[256] = {0};
  char *variable=&quot;value&quot;;

  sprintf(cmd,&quot;mddriver %s&quot;,variable);

  system(cmd);

}
bluenote@uyuyuy.com
(excuse my english)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top