what is the function that acts like SYSTEM(const char *) and takes no const char but a dynamic produced query
i want to write a program that will create a file by passing the string to th开发者_如何学Goe shell at program executes . this can be done by the system() but i want to use this function , for many arguments in a loop . using system(char *) its giving error . is there any other way
i tried a lot plz somebody help me .
Conversion from char*
to const char*
is implicit and will work. The problem is elsewhere.
const char *s
has nothing to do with what it expects to find in s
. It is a promise to you, made by the function, that the function will not modify the contents of s
.
You can either use system
as mentioned and programmatically modify the char *
that you pass it, or you can use a function of the exec
family (exec
, execve
, execvp
, etc... depending on what is available on your system).
Please read the man of system
and exec
carefully: they do not do exactly the same thing. You may want to have a look at the man of fork
as well if you go the exec
way.
It sounds like you're looking for execv. The behavior isn't quite identical, but it's close. See also execl. They share the same man page.
精彩评论