system()执行脚本问题?
时间:2008-05-10 21:51:02
来源:论坛整理 作者: 编辑:chinaitzhe
我写了一个测试程序,如下
//运行一个脚本
//
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
int main()
{
int rec;
rec = system("/opt/bin/username/useradd.sh fff ff enable");
if(rec == 0)
printf("liu");
else
printf("tao");
}
useradd.sh 是添加用户,三个参数是用户名、密码、权限
程序执行没有问题,用户添加成功。
但是,我在一个cgi程序里,运行同样的system("/opt/bin/username/useradd.sh fff ff enable");
程序出错,网页显示错误。假如注释system("/opt/bin/username/useradd.sh fff ff enable"); 网页正常显示。
网友回复:system
--------------------------------------------------------------------------------
Executes a shell command
#include <stdlib.h>
int system ( const char *s );
The system( ) function passes a command line addressed by the pointer argument s to an operating system shell. If s is a null pointer, the function returns true (a nonzero value) if a command processor is available to handle shell commands, and 0 or false if not.
How the system executes a command, and what value the system( ) function returns, are left up to the given implementation. The command may terminate the program that calls system( ), or have unspecified effects on its further behavior.
Example
if ( system( NULL ))
system( "echo \"Shell: $SHELL; process ID: $$\"");
else
printf( "No command processor available.\n" );
This example is not portable, but on certain systems it can produce output like this:
Shell: /usr/local/bin/bash; process ID: 21349
例子:
删除文件
system("rm -f $TMP_DIR/xxx.dat >& /dev/null");
网友回复:确认运行id有读 执行/opt/bin/username/useradd.sh 的权限,同时也要确认这个文件真的存在
可能要用sh /opt/bin/username/useradd.sh 来执行
网友回复:CGI的系统调用的权限问题
建议
system("sudo /opt/bin/username/useradd.sh fff ff enable")
system的返回值是1--127。
网友回复:
CGI的系统调用的权限问题
建议
system("sudo /opt/bin/username/useradd.sh fff ff enable")
system的返回值是1--127。
zoeman :sudo 代表的是什么,目录吗?
网友回复:sudo -->> superuser do
不过需要用户在sudo组中
网友回复:听说system不安全,调用execlp(),能行,但是只要调用system()功能实现了,但是cgi程序的网页出错。
关键字:system,执行,脚本,问题,
上一篇:马上毕业,散分。
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面