c++ - 将非 char* 参数传递给 execvp

标签 c++ unix execvp

基本上,我想执行一个名为“worker”的程序,其中包含 6 个整数参数...

char* args[7] = {(char*)"worker",workerID,i+1,msgID,shmID,semaphoreID,NULL};
if(execvp("worker",args)<0){
    cerr << "execvp failed" << endl;
    exit(1);
}

我如何正确地将它们转换为类型 char* ? 我已经尝试在 (char*) 前面添加并使用 stringstream 将它们存储在 char 数组中,但我仍然遇到编译器错误。

最佳答案

您需要将它们实际转换为字符串。看看 sprintf 或这个 SO 问题:

Where is the itoa function in Linux?

关于c++ - 将非 char* 参数传递给 execvp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15306400/

相关文章:

http - 登录命令行后执行GET请求

c - 来自 execvp 的段错误

c - 管道问题 : first child writes too much in to pipe

c++ - 通过 atomic::load() 访问 vector 时发生访问冲突

c++ - 为 std::pair<int, int> 重载运算符>>

c++ - 使用 MySQL++ 抛出 EXC_BAD_ACCESS

linux - 如何找到处理 bash 管道的进程

java - 我们可以通过对象引用找到 Unix Pid 吗?

c - 在 C 程序中使用 execvp 运行命令

c++ - 从数组构造 std::set