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, 1177👍, 0💬
Popular Posts:
Describe different elements in Static Chart diagrams ? Package: - It logically groups element of a U...
How To Empty Your Recycle Bin? - Oracle DBA FAQ - Managing Oracle Database Tables If your recycle bi...
An application needs to load a library before it starts to run, how to code? One option is to use a ...
What would you use to compare two String variables - the operator == or the method equals()? You can...
What is difference between SITP and UTP in testing ? UTP (Unit Test Plan) are done at smallest unit ...