开发者

what is the function that acts like SYSTEM(const char *) and takes no const char but a dynamic produced query

开发者 https://www.devze.com 2023-01-23 07:11 出处:网络
i want to write a program that will create a fileby passing the string to th开发者_如何学Goe shell atprogram executes . this can be done by the system()

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消