This is the mail archive of the cygwin mailing list for the Cygwin project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Volker Quetschke wrote: > Basically (see the attached example program) D'oh! I forgot the attachment. Volker -- PGP/GPG key (ID: 0x9F8A785D) available from wwwkeys.de.pgp.net key-fingerprint 550D F17E B082 A3E9 F913 9E53 3D35 C9BA 9F8A 785D
#include <string>
#include <iostream>
#include <cstddef>
#include <cerrno>
using std::string;
using std::size_t;
int main() {
const char *nargv[3];
string arg1("echo");
nargv[0] = arg1.c_str();
string arg2("test");
nargv[1] = arg2.c_str();
nargv[2] = NULL;
// Unfortunately the prototype of execvp does not like const char*,
// actually not const char* nargv[] coming from .c_str(). So either
// we copy everything into newly allocated variables or we force it
// with a cast. const_cast<char * const *>() - Is this OK?
if ( execvp(nargv[0], const_cast<char * const *>(nargv) ) < 0 ) {
perror("Execvp error. Aborting.");
exit(1);
}
return 1;
}
Attachment:
signature.asc
Description: OpenPGP digital signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |