Reputation: 977
I want to use a exe file (convert.exe), inside my C++ program. This "exe" file change my output file format to another format. when, i use this convert.exe from my command-prompt (cmd), i have to type like this;
convert -in myfile -out convertedfile -n -e -h
where;
myfile= name of the file, I obtain from my c++ program convertedfile= result of the "convert.exe" file -n, -e, -h = are some parameters (columns) that i need to use to get output file with my desired data columns.
i tried with system(convert.exe). but, it does not work as i did not know how to use all those parameters.
Upvotes: 15
Views: 48995
Reputation: 4270
The std::system
function expects a const char *
, so how about you try
system("convert -in myfile -out convertedfile -n -e -h")
Then, if you want to be a little more flexible, you use std::sprintf
can create a string with the right elements in it and then pass it to the system() function like so:
// create a string, i.e. an array of 50 char
char command[50];
// this will 'fill' the string command with the right stuff,
// assuming myFile and convertedFile are strings themselves
sprintf (command, "convert -in %s -out %s -n -e -h", myFile, convertedFile);
// system call
system(command);
Upvotes: 18
Reputation: 29
system (command); from stdlib.h
Since you don't want parallel execution wouldn't three consecutive calls to the execs with system () work for you?
Upvotes: 1
Reputation: 8188
Use one of these:
int execl(char * pathname, char * arg0, arg1, ..., argn, NULL);
int execle(char * pathname, char * arg0, arg1,..., argn, NULL, char ** envp);
int execlp(char * pathname, char * arg0, arg1,..., argn, NULL);
int execlpe(char * pathname, char * arg0, arg1,..., argn, NULL, char ** envp);int execv(char * pathname, char * argv[]);
int execve(char * pathname, char * argv[], char ** envp);
int execvp(char * pathname, char * argv[]);
int execvpe(char * pathname, char * argv[],char ** envp);
exec() family of functions creates a new process image from a regular, executable file...
Upvotes: 1
Reputation: 8382
Have a look at the ShellExecute function:
ShellExecute(NULL, "open", "<fully_qualified_path_to_executable>\convert.exe",
"-in myfile -out convertedfile -n -e -h",
NULL, SW_SHOWNORMAL);
Upvotes: 4