简体   繁体   English

如何在C ++ execve命令中将字符串转换为char [] *?

[英]How do you convert a string to a char[]* in C++ execve command?

When trying to use the execve command, I receive an error about my last 2 arguments. 尝试使用execve命令时,我收到有关最后两个参数的错误。

     #include <unistd.h>        
     const char * c = enviorment.c_str();
     execve(full.c_str() , cl.getArgVector(), c);

I've tried using the several different options in copying strings such as: 我尝试在复制字符串时使用几个不同的选项,例如:

char *temp2 = new char[(path).size()+1];
strcpy ( temp2, cl.getCommand());
    execve(full.c_str() , cl.getArgVector(), temp);

but I'm unable to get it to work and recieve an error message: 但我无法使其正常工作并收到错误消息:

error: cannot convert char* to char* const* for argument 3 to int execve(const char*, char* const*, char* const*) 错误:无法将参数3的char *转换为char * const *到int execve(const char *,char * const *,char * const *)

The environment variable array is an array of strings (char*), not one string. 环境变量数组是一个字符串数组(char *),而不是一个字符串。 It needs a NULL value as the final element in the array. 它需要一个NULL值作为数组中的最后一个元素。

Mimic the code you're using to implement c1.getArgVector() making sure the last char* in the array is NULL. 模仿用于实现c1.getArgVector()的代码,确保数组中的最后一个char *为NULL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM