Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I call system when parameters (filenames, etc.) of the executed command arent known until run time?
How can I call system when parameters (filenames, etc.) of the executed command arent known until run time?
✍: Guest
Just 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... */
2015-03-18, 1224👍, 0💬
Popular Posts:
When should the register modifier be used? Does it really help? The register modifier hints to the c...
What is application domain? Explain. An application domain is the CLR equivalent of an operation sys...
What would you use to compare two String variables - the operator == or the method equals()? You can...
What will be printed as the result of the operation below: main() { char s1[]="Cisco"; char s2[]="sy...
How can you check to see whether a symbol is defined? You can use the #ifdef and #ifndef preprocesso...