Ç - 试图通过/斌/ ls以execvp时错误 [英] C - error when attempting to pass /bin/ls to execvp

查看:239
本文介绍了Ç - 试图通过/斌/ ls以execvp时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,需要能够使用execvp执行某些命令的C程序,我已经实现了这个有:

I am working on a C program that needs to be able to execute certain commands using execvp, and I have implemented this with:

execvp(参数[0],参数);

其中,参数[] 是刺的数组。在大多数情况下,我的执行工作正常 - 例如如果参数 {摸,somefile.txt} 那么触摸如预期的命令被调用。

where arguments[] is an array of stings. For the most part, my implementation works fine - e.g. if arguments is {"touch", "somefile.txt"} then the touch command is called as expected.

然而,当我试图传递 LS 带参数是类似 {/斌/ LS,-a来execvp, 。} ,功能LS打印效果与预期的目录列表,还输出错误

However, when I attempt to pass ls to execvp with arguments being something like {"/bin/ls", "-a", "."}, the ls function prints the directory listing as expected but also prints the error

LS:无法访问GLIBC_2.0:没有这样的文件或目录

我不知道如何解决这个警告,谷歌搜索已经变成了什么。任何想法有什么不好?

I have no idea how to resolve this warning, and a google search has turned up nothing. Any ideas what is wrong?

推荐答案

execvp 的手册页说:

execv() execvp()函数提供的指针数组
  空值终止字符串重新present可用参数列表
  新方案。第一个参数,按照惯例,应该指向
  正在执行与文件相关联的文件名。 的数组
  指针必须由一个NULL指针终止。

The execv() and execvp() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer.

这篇关于Ç - 试图通过/斌/ ls以execvp时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆