This is a discussion on How can I call system in C? within the C and C++ Programming forums, part of the Software Development category; How can I call system when parameters (filenames, etc.) of the executed command aren't known until run time?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, when use sprintf (or perhaps strcpy and strcat) to build the command string in a buffer, then call system with that buffer. (Make sure the buffer is allocated with enough space Here is a contrived example suggesting how you might build a data file, then sort it (assuming the existence of a sort utility, and Unix- or MS-DOS-style input/output redirection): char *datafile = "file.dat"; char *sortedfile = "file.sort"; char cmdbuf[50]; FILE *fp = fopen(datafile, "w"); /* ...write to fp to build data file... */ fclose(fp); sprintf(cmdbuf, "sort < %s > %s", datafile, sortedfile); system(cmdbuf); fp = fopen(sortedfile, "r"); /* ...now read sorted data from fp... */ Thanks Prasath.K |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Difference between System.String and System.StringBuilder class? | S.Vinothkumar | C# Programming | 1 | 10-29-2007 05:23 AM |
| difference between call by value and call by reference | amansundar | Java Programming | 2 | 09-18-2007 01:34 AM |
| What’s the difference between the System.Array.CopyTo() and System.Array.Clone() ? | Archer | C# Programming | 2 | 08-25-2007 03:00 AM |
| Function call and System call | vigneshgets | Operating Systems | 1 | 08-01-2007 06:18 AM |
| How Do I Call Java from C? | kingmaker | C and C++ Programming | 1 | 07-30-2007 07:58 AM |